-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support to specify SDK by element.
Adds syntax for <Sdk> element. This is identical to using the <Project Sdk="" /> attribute and results in an implicit import at the top and bottom of the project.
- Loading branch information
1 parent
dfcf598
commit b9aa944
Showing
11 changed files
with
245 additions
and
45 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,86 @@ | ||
using Microsoft.Build.Internal; | ||
using Microsoft.Build.Shared; | ||
|
||
namespace Microsoft.Build.Construction | ||
{ | ||
/// <summary> | ||
/// ProjectSdkElement represents the Sdk element within the MSBuild project. | ||
/// </summary> | ||
public class ProjectSdkElement : ProjectElementContainer | ||
{ | ||
/// <summary> | ||
/// Initialize a parented ProjectSdkElement | ||
/// </summary> | ||
internal ProjectSdkElement(XmlElementWithLocation xmlElement, ProjectRootElement parent, | ||
ProjectRootElement containingProject) | ||
: base(xmlElement, parent, containingProject) | ||
{ | ||
ErrorUtilities.VerifyThrowArgumentNull(parent, "parent"); | ||
} | ||
|
||
/// <summary> | ||
/// Initialize an non-parented ProjectSdkElement | ||
/// </summary> | ||
private ProjectSdkElement(XmlElementWithLocation xmlElement, ProjectRootElement containingProject) | ||
: base(xmlElement, null, containingProject) | ||
{ } | ||
|
||
/// <summary> | ||
/// Gets or sets the name of the SDK. | ||
/// </summary> | ||
public string Name | ||
{ | ||
get { return ProjectXmlUtilities.GetAttributeValue(XmlElement, XMakeAttributes.sdkName); } | ||
set | ||
{ | ||
ErrorUtilities.VerifyThrowArgumentLength(value, XMakeAttributes.sdkName); | ||
ProjectXmlUtilities.SetOrRemoveAttribute(XmlElement, XMakeAttributes.sdkName, value); | ||
MarkDirty($"Set SDK Version to {value}", XMakeAttributes.sdkName); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the version of the SDK. | ||
/// </summary> | ||
public string Version | ||
{ | ||
get { return ProjectXmlUtilities.GetAttributeValue(XmlElement, XMakeAttributes.sdkVersion); } | ||
set | ||
{ | ||
ProjectXmlUtilities.SetOrRemoveAttribute(XmlElement, XMakeAttributes.sdkVersion, value); | ||
MarkDirty($"Set SDK Version to {value}", XMakeAttributes.sdkVersion); | ||
} | ||
} | ||
|
||
/// <inheritdoc /> | ||
internal override void VerifyThrowInvalidOperationAcceptableLocation(ProjectElementContainer parent, | ||
ProjectElement previousSibling, ProjectElement nextSibling) | ||
{ | ||
ErrorUtilities.VerifyThrowInvalidOperation(parent is ProjectRootElement, "OM_CannotAcceptParent"); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override ProjectElement CreateNewInstance(ProjectRootElement owner) | ||
{ | ||
return owner.CreateProjectSdkElement(Name, Version); | ||
} | ||
|
||
/// <summary> | ||
/// Creates a non-parented ProjectSdkElement, wrapping an non-parented XmlElement. | ||
/// Caller should then ensure the element is added to a parent | ||
/// </summary> | ||
internal static ProjectSdkElement CreateDisconnected(string sdkName, string sdkVersion, | ||
ProjectRootElement containingProject) | ||
{ | ||
var element = containingProject.CreateElement(XMakeElements.sdk); | ||
|
||
var sdkElement = new ProjectSdkElement(element, containingProject) | ||
{ | ||
Name = sdkName, | ||
Version = sdkVersion | ||
}; | ||
|
||
return sdkElement; | ||
} | ||
} | ||
} |
Oops, something went wrong.