-
Notifications
You must be signed in to change notification settings - Fork 698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding support for dotnet add package command #1063
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Major changes needed:
- Pass a delegate in for dotnet msbuild
- Make methods async instead of calling .Result
|
||
$installDotnet = Join-Path $CLIRootTest "dotnet-install.ps1" | ||
|
||
wget 'https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0/scripts/obtain/dotnet-install.ps1' -OutFile $installDotnet |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use a url containing the commit hash, this script commonly changes
var sources = addpkg.Option( | ||
"-s|--sources", | ||
Strings.AddPkg_SourcesDescription, | ||
CommandOptionType.SingleValue); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should match restore and take multiple values
https://github.com/dotnet/cli/blob/rel/1.0.0/src/dotnet/commands/dotnet-restore/Program.cs#L33-L36
var frameworks = addpkg.Option( | ||
"-f|--frameworks", | ||
Strings.AddPkg_FrameworksDescription, | ||
CommandOptionType.SingleValue); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this allow multiple?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And why is the name plural for a single value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the same framework parameter as build does
CommandOptionType.SingleValue); | ||
|
||
var packageDirectory = addpkg.Option( | ||
"--package-directory", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use --packages
This command should match the other commands as close as possible
https://github.com/dotnet/cli/blob/rel/1.0.0/src/dotnet/commands/dotnet-restore/Program.cs#L38-L41
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thats misleading. --packages
implies you want to add reference to multiple packages!
var packageRefArgs = new PackageReferenceArgs(dotnetPath.Value(), projectPath.Value(), packageDependency, logger) | ||
{ | ||
Frameworks = StringUtility.Split(frameworks.Value()), | ||
Sources = StringUtility.Split(sources.Value()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just allow multiple values instead of splitting this yourself, it is inconsistent with the other commands
@@ -337,4 +337,80 @@ For more information, visit http://docs.nuget.org/docs/reference/command-line-re | |||
usage: NuGet locals <all | http-cache | global-packages | temp> [--clear | -c | --list | -l] | |||
For more information, visit http://docs.nuget.org/docs/reference/command-line-reference</value> | |||
</data> | |||
<data name="Error_MSBuildUnableToOpenProject" xml:space="preserve"> | |||
<value>MSBuild was unable to open Project '{0}'.</value> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: lowecase p
<value>Failed to locate dotnet in dotnet add pkg command.</value> | ||
</data> | ||
<data name="Error_FailedToCreateRandomFile" xml:space="preserve"> | ||
<value>Failed to create random file for dotnet add pkg command.</value> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not know what to do with this message as a user. Write out the path instead.
var projectRootElement = TryOpenProjectRootElement(projectCSProjPath); | ||
if (projectCSProjPath == null) | ||
{ | ||
throw new Exception(string.Format(CultureInfo.CurrentCulture, Strings.Error_MSBuildUnableToOpenProject)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the format needed here?
var projectRootElement = TryOpenProjectRootElement(projectCSProjPath); | ||
if (projectCSProjPath == null) | ||
{ | ||
throw new Exception(string.Format(CultureInfo.CurrentCulture, Strings.Error_MSBuildUnableToOpenProject)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove format
|
||
namespace NuGet.Common | ||
{ | ||
public class TempFile : IDisposable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs clean up, copying classes from test to production code doesn't work. This shouldn't use any sub folders under /tmp for linux to avoid permission issues
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this used anywhere now?
.Where(t => t.Success) | ||
.Select(t => t.Graph.Framework)); | ||
|
||
if (packageReferenceArgs.Frameworks?.Any() == true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for == true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
packageReferenceArgs.Frameworks?.Any()
is a bool?
and if(bool?)
is not a valid statement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall great ✨
This needs a few small fixes and then
- Check GetAllUnresolved() and handle errors
- Remove unused loc strings/helper methods
- TempFile doesn't look like it is used now, it might be better to avoid that change for now.
@@ -164,6 +178,41 @@ public LockFile AssetsFile | |||
} | |||
} | |||
|
|||
public PackageSpec PackageSpec |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
|
||
namespace NuGet.Common | ||
{ | ||
public class TempFile : IDisposable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this used anywhere now?
{ | ||
if (File.Exists(_filePath)) | ||
{ | ||
File.Delete(_filePath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't clean up the folder
var tempDirectory = Path.GetTempPath(); | ||
var randomFolderName = Guid.NewGuid().ToString(); | ||
var randomFileName = Guid.NewGuid().ToString(); | ||
Directory.CreateDirectory(Path.Combine(tempDirectory, randomFolderName)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see a need for a sub directory here. Just create it in the temp root.
|
||
namespace NuGet.Common | ||
{ | ||
public static class StringUtility |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MSBuild helpers should not be in Common
@@ -337,4 +337,81 @@ For more information, visit http://docs.nuget.org/docs/reference/command-line-re | |||
usage: NuGet locals <all | http-cache | global-packages | temp> [--clear | -c | --list | -l] | |||
For more information, visit http://docs.nuget.org/docs/reference/command-line-reference</value> | |||
</data> | |||
<data name="Error_MSBuildUnableToOpenProject" xml:space="preserve"> | |||
<value>msbuild was unable to open Project '{0}'.</value> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: lowercase project
<value>msbuild was unable to open Project '{0}'.</value> | ||
<comment>{0} - Project/csproj path</comment> | ||
</data> | ||
<data name="Error_DotnetNotFound" xml:space="preserve"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove unused strings I see quite a few in here that are no longer used.
packageReferenceArgs.Logger.LogDebug("Project Dependency Graph Read"); | ||
|
||
var projectName = dgSpec.Restore.FirstOrDefault(); | ||
var originalPackageSpec = dgSpec.GetProjectSpec(projectName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks like it could crash if the dg spec wasn't passed in and an empty one was returned, maybe throw a helpful error message instead
} | ||
} | ||
|
||
private static void LogQueue(ConcurrentQueue<string> outputs, ILogger logger) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see these helper methods being used anywhere now
|
||
// 2. Run Restore Preview | ||
packageReferenceArgs.Logger.LogDebug("Running Restore preview"); | ||
var restorePreviewResult = await PreviewAddPackageReference(packageReferenceArgs, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
checking Success wont work here, but you should verify GetAllUnresolved() == 0
It is possible the packages were missing or couldn't be downloaded. If that happens they won't show in the compat check since there was nothing to verify. Later it will null ref when they are missing from the graph.
merged : dd0f0aa |
Fixes : NuGet/Home#3751
This PR adds a new xplat command to allow users to add package references though dotnet cli.
Objectives -
add package
command to allow users to add package reference into csproj files through dotnet cli as part of https://github.com/dotnet/cli/issues/4521root/cli_test
to enable testing.SimplePackageContext()
//cc: @emgarten @joelverhagen @rohit21agrawal @rrelyea @zhili1208 @jainaashish @alpaix @nkolev92
Nvm the number of commits, will squash and merge!