-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Add support for SDK Resolvers #2002
Merged
Merged
Changes from all commits
Commits
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
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
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 |
---|---|---|
|
@@ -308,6 +308,7 @@ internal ProjectRootElement() { } | |
public Microsoft.Build.Construction.ProjectOtherwiseElement CreateOtherwiseElement() { throw null; } | ||
public Microsoft.Build.Construction.ProjectOutputElement CreateOutputElement(string taskParameter, string itemType, string propertyName) { throw null; } | ||
public Microsoft.Build.Construction.ProjectExtensionsElement CreateProjectExtensionsElement() { throw null; } | ||
public Microsoft.Build.Construction.ProjectSdkElement CreateProjectSdkElement(string sdkName, string sdkVersion) { throw null; } | ||
public Microsoft.Build.Construction.ProjectPropertyElement CreatePropertyElement(string name) { throw null; } | ||
public Microsoft.Build.Construction.ProjectPropertyGroupElement CreatePropertyGroupElement() { throw null; } | ||
public Microsoft.Build.Construction.ProjectTargetElement CreateTargetElement(string name) { throw null; } | ||
|
@@ -334,6 +335,14 @@ public void Save(System.Text.Encoding saveEncoding) { } | |
public static Microsoft.Build.Construction.ProjectRootElement TryOpen(string path, Microsoft.Build.Evaluation.ProjectCollection projectCollection) { throw null; } | ||
public static Microsoft.Build.Construction.ProjectRootElement TryOpen(string path, Microsoft.Build.Evaluation.ProjectCollection projectCollection, System.Nullable<bool> preserveFormatting) { throw null; } | ||
} | ||
public partial class ProjectSdkElement : Microsoft.Build.Construction.ProjectElementContainer | ||
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. Did we get conceptual buy off on this from the people that vetoed it before? |
||
{ | ||
internal ProjectSdkElement() { } | ||
public string MinimumVersion { get { throw null; } set { } } | ||
public string Name { get { throw null; } set { } } | ||
public string Version { get { throw null; } set { } } | ||
protected override Microsoft.Build.Construction.ProjectElement CreateNewInstance(Microsoft.Build.Construction.ProjectRootElement owner) { throw null; } | ||
} | ||
[System.Diagnostics.DebuggerDisplayAttribute("Name={Name} #Children={Count} Condition={Condition}")] | ||
public partial class ProjectTargetElement : Microsoft.Build.Construction.ProjectElementContainer | ||
{ | ||
|
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
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
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 |
---|---|---|
|
@@ -36,49 +36,71 @@ public ProjectSdkImplicitImport_Tests() | |
Directory.CreateDirectory(_testSdkDirectory); | ||
} | ||
|
||
[Fact] | ||
public void SdkImportsAreInLogicalProject() | ||
[Theory] | ||
[InlineData(@" | ||
<Project Sdk=""{0}""> | ||
<PropertyGroup> | ||
<UsedToTestIfImplicitImportsAreInTheCorrectLocation>null</UsedToTestIfImplicitImportsAreInTheCorrectLocation> | ||
</PropertyGroup> | ||
</Project> | ||
")] | ||
[InlineData(@" | ||
<Project> | ||
<Sdk Name=""{0}"" /> | ||
<PropertyGroup> | ||
<UsedToTestIfImplicitImportsAreInTheCorrectLocation>null</UsedToTestIfImplicitImportsAreInTheCorrectLocation> | ||
</PropertyGroup> | ||
</Project> | ||
")] | ||
public void SdkImportsAreInLogicalProject(string projectFormatString) | ||
{ | ||
File.WriteAllText(_sdkPropsPath, "<Project><PropertyGroup><InitialImportProperty>Hello</InitialImportProperty></PropertyGroup></Project>"); | ||
File.WriteAllText(_sdkTargetsPath, "<Project><PropertyGroup><FinalImportProperty>World</FinalImportProperty></PropertyGroup></Project>"); | ||
|
||
using (new Helpers.TemporaryEnvironment("MSBuildSDKsPath", _testSdkRoot)) | ||
{ | ||
string content = $@" | ||
<Project Sdk=""{SdkName}""> | ||
<PropertyGroup> | ||
<UsedToTestIfImplicitImportsAreInTheCorrectLocation>null</UsedToTestIfImplicitImportsAreInTheCorrectLocation> | ||
</PropertyGroup> | ||
</Project>"; | ||
string content = string.Format(projectFormatString, SdkName); | ||
|
||
ProjectRootElement projectRootElement = ProjectRootElement.Create(XmlReader.Create(new StringReader(content))); | ||
|
||
Project project = new Project(projectRootElement); | ||
var project = new Project(projectRootElement); | ||
|
||
IList<ProjectElement> children = project.GetLogicalProject().ToList(); | ||
|
||
Assert.Equal(6, children.Count); | ||
|
||
// <Sdk> style will have an extra ProjectElment. | ||
var expected = projectFormatString.Contains("Sdk=") ? 6 : 7; | ||
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. Make this an input instead? (Can wait for a cleanup PR) |
||
Assert.Equal(expected, children.Count); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void SdkImportsAreInImportList() | ||
[Theory] | ||
[InlineData(@" | ||
<Project Sdk=""{0}""> | ||
<PropertyGroup> | ||
<UsedToTestIfImplicitImportsAreInTheCorrectLocation>null</UsedToTestIfImplicitImportsAreInTheCorrectLocation> | ||
</PropertyGroup> | ||
</Project> | ||
")] | ||
[InlineData(@" | ||
<Project> | ||
<Sdk Name=""{0}"" /> | ||
<PropertyGroup> | ||
<UsedToTestIfImplicitImportsAreInTheCorrectLocation>null</UsedToTestIfImplicitImportsAreInTheCorrectLocation> | ||
</PropertyGroup> | ||
</Project> | ||
")] | ||
public void SdkImportsAreInImportList(string projectFormatString) | ||
{ | ||
File.WriteAllText(_sdkPropsPath, "<Project><PropertyGroup><InitialImportProperty>Hello</InitialImportProperty></PropertyGroup></Project>"); | ||
File.WriteAllText(_sdkTargetsPath, "<Project><PropertyGroup><FinalImportProperty>World</FinalImportProperty></PropertyGroup></Project>"); | ||
|
||
using (new Helpers.TemporaryEnvironment("MSBuildSDKsPath", _testSdkRoot)) | ||
{ | ||
string content = $@" | ||
<Project Sdk=""{SdkName}""> | ||
<PropertyGroup> | ||
<UsedToTestIfImplicitImportsAreInTheCorrectLocation>null</UsedToTestIfImplicitImportsAreInTheCorrectLocation> | ||
</PropertyGroup> | ||
</Project>"; | ||
string content = string.Format(projectFormatString, SdkName); | ||
|
||
ProjectRootElement projectRootElement = ProjectRootElement.Create(XmlReader.Create(new StringReader(content))); | ||
|
||
Project project = new Project(projectRootElement); | ||
var project = new Project(projectRootElement); | ||
|
||
// The XML representation of the project should indicate there are no imports | ||
Assert.Equal(0, projectRootElement.Imports.Count); | ||
|
@@ -103,8 +125,17 @@ public void SdkImportsAreInImportList() | |
/// <summary> | ||
/// Verifies that when a user specifies more than one SDK that everything works as expected | ||
/// </summary> | ||
[Fact] | ||
public void SdkSupportsMultiple() | ||
[Theory] | ||
[InlineData(@" | ||
<Project Sdk=""{0};{1};{2}""> | ||
</Project >")] | ||
[InlineData(@" | ||
<Project> | ||
<Sdk Name=""{0}"" /> | ||
<Sdk Name=""{1}"" /> | ||
<Sdk Name=""{2}"" /> | ||
</Project>")] | ||
public void SdkSupportsMultiple(string projectFormatString) | ||
{ | ||
IList<string> sdkNames = new List<string> | ||
{ | ||
|
@@ -123,10 +154,7 @@ public void SdkSupportsMultiple() | |
|
||
using (new Helpers.TemporaryEnvironment("MSBuildSDKsPath", _testSdkRoot)) | ||
{ | ||
string content = $@" | ||
<Project Sdk=""{String.Join("; ", sdkNames)}""> | ||
|
||
</Project>"; | ||
string content = string.Format(projectFormatString, sdkNames[0], sdkNames[1], sdkNames[2]); | ||
|
||
ProjectRootElement projectRootElement = ProjectRootElement.Create(XmlReader.Create(new StringReader(content))); | ||
|
||
|
@@ -144,8 +172,13 @@ public void SdkSupportsMultiple() | |
} | ||
} | ||
|
||
[Fact] | ||
public void ProjectWithSdkImportsIsCloneable() | ||
[Theory] | ||
[InlineData(@"<Project Sdk=""{0}"" ToolsVersion=""15.0""> | ||
")] | ||
[InlineData(@"<Project ToolsVersion=""15.0""> | ||
<Sdk Name=""{0}"" /> | ||
")] | ||
public void ProjectWithSdkImportsIsCloneable(string projectFileFirstLineFormat) | ||
{ | ||
File.WriteAllText(_sdkPropsPath, "<Project />"); | ||
File.WriteAllText(_sdkTargetsPath, "<Project />"); | ||
|
@@ -154,7 +187,7 @@ public void ProjectWithSdkImportsIsCloneable() | |
{ | ||
// Based on the new-console-project CLI template (but not matching exactly | ||
// should not be a deal-breaker). | ||
string content = $@"<Project Sdk=""{SdkName}"" ToolsVersion=""15.0""> | ||
string content = $@"{string.Format(projectFileFirstLineFormat, SdkName)} | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp1.0</TargetFramework> | ||
|
@@ -177,8 +210,13 @@ public void ProjectWithSdkImportsIsCloneable() | |
} | ||
} | ||
|
||
[Fact] | ||
public void ProjectWithSdkImportsIsRemoveable() | ||
[Theory] | ||
[InlineData(@"<Project Sdk=""{0}"" ToolsVersion=""15.0""> | ||
")] | ||
[InlineData(@"<Project ToolsVersion=""15.0""> | ||
<Sdk Name=""{0}"" /> | ||
")] | ||
public void ProjectWithSdkImportsIsRemoveable(string projectFileFirstLineFormat) | ||
{ | ||
File.WriteAllText(_sdkPropsPath, "<Project />"); | ||
File.WriteAllText(_sdkTargetsPath, "<Project />"); | ||
|
@@ -187,7 +225,7 @@ public void ProjectWithSdkImportsIsRemoveable() | |
{ | ||
// Based on the new-console-project CLI template (but not matching exactly | ||
// should not be a deal-breaker). | ||
string content = $@"<Project Sdk=""{SdkName}"" ToolsVersion=""15.0""> | ||
string content = $@"{string.Format(projectFileFirstLineFormat, SdkName)} | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp1.0</TargetFramework> | ||
|
@@ -260,6 +298,30 @@ public void ProjectWithEmptySdkName() | |
} | ||
} | ||
|
||
/// <summary> | ||
/// Verifies that an empty SDK attribute works and nothing is imported. | ||
/// </summary> | ||
[Fact] | ||
public void ProjectWithEmptySdkNameElementThrows() | ||
{ | ||
using (new Helpers.TemporaryEnvironment("MSBuildSDKsPath", _testSdkRoot)) | ||
{ | ||
string content = @" | ||
<Project> | ||
<Sdk Name="""" /> | ||
<PropertyGroup> | ||
<UsedToTestIfImplicitImportsAreInTheCorrectLocation>null</UsedToTestIfImplicitImportsAreInTheCorrectLocation> | ||
</PropertyGroup> | ||
</Project>"; | ||
|
||
var e = | ||
Assert.Throws<InvalidProjectFileException>(() => new Project( | ||
ProjectRootElement.Create(XmlReader.Create(new StringReader(content))))); | ||
|
||
Assert.Equal("MSB4238", e.ErrorCode); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Verifies that an error occurs when one or more SDK names are empty. | ||
/// </summary> | ||
|
Oops, something went wrong.
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.
I really hope we can come up with a better implementation here but we can always ignore this field in the future so it should be reasonably harmless.