FIxing argument adding
This commit is contained in:
parent
3a5b89c242
commit
0f6e4e3f10
1 changed files with 41 additions and 27 deletions
|
@ -40,27 +40,27 @@ namespace Microsoft.DotNet.Tools.Add.PackageReference
|
||||||
command.HelpOption("-h|--help");
|
command.HelpOption("-h|--help");
|
||||||
|
|
||||||
command._versionOption = command.Option(
|
command._versionOption = command.Option(
|
||||||
$"-v|--version",
|
"-v|--version",
|
||||||
LocalizableStrings.CmdVersionDescription,
|
LocalizableStrings.CmdVersionDescription,
|
||||||
CommandOptionType.SingleValue);
|
CommandOptionType.SingleValue);
|
||||||
|
|
||||||
command._frameworkOption = command.Option(
|
command._frameworkOption = command.Option(
|
||||||
$"-f|--framework",
|
$"-f|--framework <{CommonLocalizableStrings.CmdFramework}>",
|
||||||
LocalizableStrings.CmdFrameworkDescription,
|
LocalizableStrings.CmdFrameworkDescription,
|
||||||
CommandOptionType.SingleValue);
|
CommandOptionType.SingleValue);
|
||||||
|
|
||||||
command._noRestoreOption = command.Option(
|
command._noRestoreOption = command.Option(
|
||||||
$"-n|--no-restore ",
|
"-n|--no-restore ",
|
||||||
LocalizableStrings.CmdNoRestoreDescription,
|
LocalizableStrings.CmdNoRestoreDescription,
|
||||||
CommandOptionType.NoValue);
|
CommandOptionType.NoValue);
|
||||||
|
|
||||||
command._sourceOption = command.Option(
|
command._sourceOption = command.Option(
|
||||||
$"-s|--source ",
|
"-s|--source ",
|
||||||
LocalizableStrings.CmdSourceDescription,
|
LocalizableStrings.CmdSourceDescription,
|
||||||
CommandOptionType.SingleValue);
|
CommandOptionType.SingleValue);
|
||||||
|
|
||||||
command._packageDirectoryOption = command.Option(
|
command._packageDirectoryOption = command.Option(
|
||||||
$"--package-directory",
|
"--package-directory",
|
||||||
LocalizableStrings.CmdPackageDirectoryDescription,
|
LocalizableStrings.CmdPackageDirectoryDescription,
|
||||||
CommandOptionType.SingleValue);
|
CommandOptionType.SingleValue);
|
||||||
|
|
||||||
|
@ -69,22 +69,33 @@ namespace Microsoft.DotNet.Tools.Add.PackageReference
|
||||||
|
|
||||||
public override int Run(string fileOrDirectory)
|
public override int Run(string fileOrDirectory)
|
||||||
{
|
{
|
||||||
|
Console.WriteLine("Waiting for debugger to attach.");
|
||||||
|
Console.WriteLine($"Process ID: {Process.GetCurrentProcess().Id}");
|
||||||
|
|
||||||
|
while (!Debugger.IsAttached)
|
||||||
|
{
|
||||||
|
System.Threading.Thread.Sleep(100);
|
||||||
|
}
|
||||||
|
Debugger.Break();
|
||||||
var projects = new ProjectCollection();
|
var projects = new ProjectCollection();
|
||||||
var msbuildProj = MsbuildProject.FromFileOrDirectory(projects, fileOrDirectory);
|
var msbuildProj = MsbuildProject.FromFileOrDirectory(projects, fileOrDirectory);
|
||||||
|
|
||||||
var x = this.Arguments;
|
|
||||||
if (RemainingArguments.Count == 0)
|
if (RemainingArguments.Count == 0)
|
||||||
{
|
{
|
||||||
throw new GracefulException(CommonLocalizableStrings.SpecifyAtLeastOneReferenceToAdd);
|
throw new GracefulException(CommonLocalizableStrings.SpecifyAtLeastOneReferenceToAdd);
|
||||||
}
|
}
|
||||||
|
|
||||||
var tempDgFilePath = CreateTemporaryFile(".dg");
|
var tempDgFilePath = string.Empty;
|
||||||
|
if(!_noRestoreOption.HasValue())
|
||||||
|
{
|
||||||
|
// Create a Dependency Graph file for the project
|
||||||
|
tempDgFilePath = CreateTemporaryFile(".dg");
|
||||||
GetProjectDependencyGraph(msbuildProj.ProjectRootElement.FullPath, tempDgFilePath);
|
GetProjectDependencyGraph(msbuildProj.ProjectRootElement.FullPath, tempDgFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
var result = NuGetCommand.Run(TransformArgs(tempDgFilePath, msbuildProj.ProjectRootElement.FullPath));
|
var result = NuGetCommand.Run(TransformArgs(tempDgFilePath, msbuildProj.ProjectRootElement.FullPath));
|
||||||
DisposeTemporaryFile(tempDgFilePath);
|
DisposeTemporaryFile(tempDgFilePath);
|
||||||
return 0;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GetProjectDependencyGraph(string projectFilePath,
|
private void GetProjectDependencyGraph(string projectFilePath,
|
||||||
|
@ -95,10 +106,10 @@ namespace Microsoft.DotNet.Tools.Add.PackageReference
|
||||||
// Pass the project file path
|
// Pass the project file path
|
||||||
args.Add(projectFilePath);
|
args.Add(projectFilePath);
|
||||||
|
|
||||||
// Pass the task as generate restore dg file
|
// Pass the task as generate restore Dependency Graph file
|
||||||
args.Add("/t:GenerateRestoreGraphFile");
|
args.Add("/t:GenerateRestoreGraphFile");
|
||||||
|
|
||||||
// Pass dg file output path
|
// Pass Dependency Graph file output path
|
||||||
args.Add(string.Format("/p:RestoreGraphOutputPath={0}{1}{2}", '"', dgFilePath, '"'));
|
args.Add(string.Format("/p:RestoreGraphOutputPath={0}{1}{2}", '"', dgFilePath, '"'));
|
||||||
|
|
||||||
var result = new MSBuildForwardingApp(args).Execute();
|
var result = new MSBuildForwardingApp(args).Execute();
|
||||||
|
@ -133,33 +144,36 @@ namespace Microsoft.DotNet.Tools.Add.PackageReference
|
||||||
"--package",
|
"--package",
|
||||||
"Newtonsoft.Json",
|
"Newtonsoft.Json",
|
||||||
"--project",
|
"--project",
|
||||||
projectFilePath,
|
projectFilePath
|
||||||
"--dg-file",
|
|
||||||
tempDgFilePath
|
|
||||||
};
|
};
|
||||||
if(_versionOption.HasValue())
|
if(_versionOption.HasValue())
|
||||||
{
|
{
|
||||||
args.Append("--version");
|
args.Add("--version");
|
||||||
args.Append(_versionOption.Value());
|
args.Add(_versionOption.Value());
|
||||||
}
|
}
|
||||||
if(_sourceOption.HasValue())
|
if(_sourceOption.HasValue())
|
||||||
{
|
{
|
||||||
args.Append("--source");
|
args.Add("--source");
|
||||||
args.Append(_sourceOption.Value());
|
args.Add(_sourceOption.Value());
|
||||||
}
|
}
|
||||||
if(_frameworkOption.HasValue())
|
if(_frameworkOption.HasValue())
|
||||||
{
|
{
|
||||||
args.Append("--framework");
|
args.Add("--framework");
|
||||||
args.Append(_frameworkOption.Value());
|
args.Add(_frameworkOption.Value());
|
||||||
}
|
|
||||||
if(_noRestoreOption.HasValue())
|
|
||||||
{
|
|
||||||
args.Append("--no-restore");
|
|
||||||
}
|
}
|
||||||
if(_packageDirectoryOption.HasValue())
|
if(_packageDirectoryOption.HasValue())
|
||||||
{
|
{
|
||||||
args.Append("--package-directory");
|
args.Add("--package-directory");
|
||||||
args.Append(_packageDirectoryOption.Value());
|
args.Add(_packageDirectoryOption.Value());
|
||||||
|
}
|
||||||
|
if(_noRestoreOption.HasValue())
|
||||||
|
{
|
||||||
|
args.Add("--no-restore");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
args.Add("--dg-file");
|
||||||
|
args.Add(tempDgFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
return args.ToArray();
|
return args.ToArray();
|
||||||
|
|
Loading…
Reference in a new issue