-
Notifications
You must be signed in to change notification settings - Fork 694
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
dotnet add package cli support for cpm projects #4700
Merged
pragnya17
merged 16 commits into
dev-feature-cpm-dotnetaddpackage
from
dev-pragnya17-AddPackageCLISupportForCPMProjects
Jul 12, 2022
Merged
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
1de7506
Add package support for cpm projects
pragnya17 41e9474
fix bug in test
pragnya17 8d78db9
Added package version parameter
pragnya17 3457cb8
Modify test names to be more readable, remove comment in strings.resx
pragnya17 2d5c9e4
Change when info is logged
pragnya17 991539a
fix indentation and existing package references lines
pragnya17 1211852
[skip ci] add basic unit test for msbuild api
9c4e593
Change name of test
4dbde7b
Add unit tests
1740334
Change name of integration test
e3c1b34
Change name to noop test
9030707
[skip ci] Use boolean to see if package version is passed in as CLI a…
4e49d93
[skip ci] Attempt to modify unit test, still need to debug
c7aef21
Revert "[skip ci] Attempt to modify unit test, still need to debug"
60655e8
[skip ci] remove repetition when reading file from disk
58a5ddf
updated tests
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,10 +21,11 @@ static MSBuildAPIUtilityTests() | |
{ | ||
MSBuildLocator.RegisterDefaults(); | ||
} | ||
|
||
[Fact] | ||
[PlatformFact(Platform.Windows)] | ||
public void GetDirectoryBuildPropsRootElementWhenItExists_Success() | ||
{ | ||
// Arrange | ||
var testDirectory = TestDirectory.Create(); | ||
|
||
var projectCollection = new ProjectCollection( | ||
|
@@ -59,18 +60,19 @@ public void GetDirectoryBuildPropsRootElementWhenItExists_Success() | |
</PropertyGroup> | ||
</Project>"; | ||
File.WriteAllText(Path.Combine(testDirectory, "projectA.csproj"), projectContent); | ||
|
||
var project = Project.FromFile(Path.Combine(testDirectory, "projectA.csproj"), projectOptions); | ||
|
||
// Act | ||
var result = new MSBuildAPIUtility(logger: new TestLogger()).GetDirectoryBuildPropsRootElement(project); | ||
|
||
// Assert | ||
Assert.Equal(Path.Combine(testDirectory, "Directory.Packages.props"), result.FullPath); | ||
} | ||
|
||
[Fact] | ||
[PlatformFact(Platform.Windows)] | ||
public void AddPackageReferenceIntoProjectFileWhenItemGroupDoesNotExist_Success() | ||
{ | ||
// Set up | ||
// Arrange | ||
var testDirectory = TestDirectory.Create(); | ||
var projectCollection = new ProjectCollection( | ||
globalProperties: null, | ||
|
@@ -89,7 +91,7 @@ public void AddPackageReferenceIntoProjectFileWhenItemGroupDoesNotExist_Success( | |
ProjectCollection = projectCollection | ||
}; | ||
|
||
// Set up project file | ||
// Arrange project file | ||
string projectContent = | ||
@$"<Project Sdk=""Microsoft.NET.Sdk""> | ||
<PropertyGroup> | ||
|
@@ -116,14 +118,15 @@ public void AddPackageReferenceIntoProjectFileWhenItemGroupDoesNotExist_Success( | |
project.Save(); | ||
|
||
// Assert | ||
Assert.Contains(@$"<PackageReference Include=""X"" />", File.ReadAllText(Path.Combine(testDirectory, "projectA.csproj"))); | ||
Assert.DoesNotContain(@$"<Version = ""1.0.0"" />", File.ReadAllText(Path.Combine(testDirectory, "projectA.csproj"))); | ||
string updatedProjectFile = File.ReadAllText(Path.Combine(testDirectory, "projectA.csproj")); | ||
Assert.Contains(@$"<PackageReference Include=""X"" />", updatedProjectFile); | ||
Assert.DoesNotContain(@$"<Version = ""1.0.0"" />", updatedProjectFile); | ||
} | ||
|
||
[Fact] | ||
[PlatformFact(Platform.Windows)] | ||
public void AddPackageReferenceIntoProjectFileWhenItemGroupDoesExist_Success() | ||
{ | ||
// Set up | ||
// Arrange | ||
var testDirectory = TestDirectory.Create(); | ||
var projectCollection = new ProjectCollection( | ||
globalProperties: null, | ||
|
@@ -142,7 +145,7 @@ public void AddPackageReferenceIntoProjectFileWhenItemGroupDoesExist_Success() | |
ProjectCollection = projectCollection | ||
}; | ||
|
||
// Set up project file | ||
// Arrange project file | ||
string projectContent = | ||
@$"<Project Sdk=""Microsoft.NET.Sdk""> | ||
<PropertyGroup> | ||
|
@@ -174,14 +177,15 @@ public void AddPackageReferenceIntoProjectFileWhenItemGroupDoesExist_Success() | |
project.Save(); | ||
|
||
// Assert | ||
Assert.Contains(@$"<PackageReference Include=""X"" />", File.ReadAllText(Path.Combine(testDirectory, "projectA.csproj"))); | ||
Assert.DoesNotContain(@$"<Version = ""1.0.0"" />", File.ReadAllText(Path.Combine(testDirectory, "projectA.csproj"))); | ||
string updatedProjectFile = File.ReadAllText(Path.Combine(testDirectory, "projectA.csproj")); | ||
Assert.Contains(@$"<PackageReference Include=""X"" />", updatedProjectFile); | ||
Assert.DoesNotContain(@$"<Version = ""1.0.0"" />", updatedProjectFile); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This always return true, so I think it should be changed to $"PackageReference Includes =""X"" <Version = ""1.0.0"" />". This is along the lines of this comment: #4700 (comment) |
||
} | ||
|
||
[Fact] | ||
[PlatformFact(Platform.Windows)] | ||
public void AddPackageVersionIntoPropsFileWhenItemGroupDoesNotExist_Success() | ||
{ | ||
// Set up | ||
// Arrange | ||
var testDirectory = TestDirectory.Create(); | ||
var projectCollection = new ProjectCollection( | ||
globalProperties: null, | ||
|
@@ -200,7 +204,7 @@ public void AddPackageVersionIntoPropsFileWhenItemGroupDoesNotExist_Success() | |
ProjectCollection = projectCollection | ||
}; | ||
|
||
// Set up Directory.Packages.props file | ||
// Arrange Directory.Packages.props file | ||
var propsFile = | ||
@$"<Project> | ||
<PropertyGroup> | ||
|
@@ -209,7 +213,7 @@ public void AddPackageVersionIntoPropsFileWhenItemGroupDoesNotExist_Success() | |
</Project>"; | ||
File.WriteAllText(Path.Combine(testDirectory, "Directory.Packages.props"), propsFile); | ||
|
||
// Set up project file | ||
// Arrange project file | ||
string projectContent = | ||
@$"<Project Sdk=""Microsoft.NET.Sdk""> | ||
<PropertyGroup> | ||
|
@@ -243,10 +247,10 @@ public void AddPackageVersionIntoPropsFileWhenItemGroupDoesNotExist_Success() | |
</ItemGroup>", File.ReadAllText(Path.Combine(testDirectory, "Directory.Packages.props"))); | ||
} | ||
|
||
[Fact] | ||
[PlatformFact(Platform.Windows)] | ||
public void AddPackageVersionIntoPropsFileWhenItemGroupExists_Success() | ||
{ | ||
// Set up | ||
// Arrange | ||
var testDirectory = TestDirectory.Create(); | ||
var projectCollection = new ProjectCollection( | ||
globalProperties: null, | ||
|
@@ -265,7 +269,7 @@ public void AddPackageVersionIntoPropsFileWhenItemGroupExists_Success() | |
ProjectCollection = projectCollection | ||
}; | ||
|
||
// Set up Directory.Packages.props file | ||
// Arrange Directory.Packages.props file | ||
var propsFile = | ||
@$"<Project> | ||
<PropertyGroup> | ||
|
@@ -277,7 +281,7 @@ public void AddPackageVersionIntoPropsFileWhenItemGroupExists_Success() | |
</Project>"; | ||
File.WriteAllText(Path.Combine(testDirectory, "Directory.Packages.props"), propsFile); | ||
|
||
// Set up project file | ||
// Arrange project file | ||
string projectContent = | ||
@$"<Project Sdk=""Microsoft.NET.Sdk""> | ||
<PropertyGroup> | ||
|
@@ -312,10 +316,10 @@ public void AddPackageVersionIntoPropsFileWhenItemGroupExists_Success() | |
Assert.Contains(@$"<PackageVersion Include=""Y"" Version=""1.0.0"" />", File.ReadAllText(Path.Combine(testDirectory, "Directory.Packages.props"))); | ||
} | ||
|
||
[Fact] | ||
[PlatformFact(Platform.Windows)] | ||
public void UpdatePackageVersionInPropsFileWhenItExists_Success() | ||
{ | ||
// Set up | ||
// Arrange | ||
var testDirectory = TestDirectory.Create(); | ||
var projectCollection = new ProjectCollection( | ||
globalProperties: null, | ||
|
@@ -334,7 +338,7 @@ public void UpdatePackageVersionInPropsFileWhenItExists_Success() | |
ProjectCollection = projectCollection | ||
}; | ||
|
||
// Set up Directory.Packages.props file | ||
// Arrange Directory.Packages.props file | ||
var propsFile = | ||
@$"<Project> | ||
<PropertyGroup> | ||
|
@@ -346,7 +350,7 @@ public void UpdatePackageVersionInPropsFileWhenItExists_Success() | |
</Project>"; | ||
File.WriteAllText(Path.Combine(testDirectory, "Directory.Packages.props"), propsFile); | ||
|
||
// Set up project file | ||
// Arrange project file | ||
string projectContent = | ||
@$"<Project Sdk=""Microsoft.NET.Sdk""> | ||
<PropertyGroup> | ||
|
@@ -376,9 +380,9 @@ public void UpdatePackageVersionInPropsFileWhenItExists_Success() | |
|
||
// Assert | ||
Assert.Equal(projectContent, File.ReadAllText(Path.Combine(testDirectory, "projectA.csproj"))); | ||
Assert.Contains(@$"<PackageVersion Include=""X"" Version=""2.0.0"" />", File.ReadAllText(Path.Combine(testDirectory, "Directory.Packages.props"))); | ||
Assert.DoesNotContain(@$"<PackageVersion Include=""X"" Version=""1.0.0"" />", File.ReadAllText(Path.Combine(testDirectory, "Directory.Packages.props"))); | ||
string updatedPropsFile = File.ReadAllText(Path.Combine(testDirectory, "Directory.Packages.props")); | ||
Assert.Contains(@$"<PackageVersion Include=""X"" Version=""2.0.0"" />", updatedPropsFile); | ||
Assert.DoesNotContain(@$"<PackageVersion Include=""X"" Version=""1.0.0"" />", updatedPropsFile); | ||
} | ||
|
||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Had an offline conversation with @pragnya17 about removing
project.Save()
method call but instead useMSBuild Project
object model to validate the result.For context,
project.Save()
is invoked here to save the modification done byAddPackageReferenceIntoItemGroupCPM
to the file system and then verify the behavior. Given that these are unit tests, I am wondering if we use the MSBuild API to validate the result instead of reading csproj or packages.props file.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 agree. However, there were some issues with debugging the unit test after making this modification so during an offline conversation, Kartheek and I agreed that he would be able to finish debugging/making these modifications to the unit tests.