-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Generate errors when referencing an Executable project with different SelfContained value #15134
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
Generate errors when referencing an Executable project with different SelfContained value #15134
Conversation
<UsingTask TaskName="ValidateExecutableReferences" AssemblyFile="$(MicrosoftNETBuildTasksAssembly)" /> | ||
|
||
<Target Name="ValidateExecutableReferences" | ||
AfterTargets="_GetProjectReferenceTargetFrameworkProperties" |
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.
Cannot make this a dependOn?
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, DependsOnTargets
and AfterTargets
mean different things: https://github.com/MicrosoftDocs/visualstudio-docs/issues/2994#issuecomment-480017831
…jects (#5994) This allows additional properties to be gathered from project references via the project reference protocol. This is in order to support generating an error when a self-contained Executable references a non-SelfContained Executable, or vice versa, as described in dotnet/sdk#15117. The referenced project can declare what additional properties should be gathered with AdditionalTargetFrameworkInfoProperty items: <ItemGroup> <AdditionalTargetFrameworkInfoProperty Include="SelfContained"/> <AdditionalTargetFrameworkInfoProperty Include="_IsExecutable"/> </ItemGroup> These items will then be included in the AdditionalPropertiesFromProject metadata on the _MSBuildProjectReferenceExistent items. This value will have PropertyName=PropertyValue combinations joined by semicolons, and those sets of properties for the different TargetFramework values will be joined by double semicolons. For example, a project multitargeted to two TargetFrameworks may have the following for the AdditionalPropertiesFromProject metadata: SelfContained=true;_IsExecutable=true;;SelfContained=false;_IsExecutable=true Finding the right set of properties from the referenced project will required looking up the index of the NearestTargetFramework in the TargetFrameworks, and using that index to select the set of properties in the AdditionalPropertiesFromProject metadata. For example: string nearestTargetFramework = project.GetMetadata("NearestTargetFramework"); int targetFrameworkIndex = project.GetMetadata("TargetFrameworks").Split(';').ToList().IndexOf(nearestTargetFramework); string projectAdditionalPropertiesMetadata = project.GetMetadata("AdditionalPropertiesFromProject").Split(new[] { ";;" }, StringSplitOptions.None)[targetFrameworkIndex]; Dictionary<string, string> projectAdditionalProperties = new(StringComparer.OrdinalIgnoreCase); foreach (var propAndValue in projectAdditionalPropertiesMetadata.Split(';')) { var split = propAndValue.Split('='); projectAdditionalProperties[split[0]] = split[1]; } This is implemented in dotnet/sdk#15134.
/azp run |
Pull request contains merge conflicts. |
It's automatically handled by MSBuild
5cfe1b0
to
cc7769c
Compare
cc7769c
to
f8c33dc
Compare
@marcpopMSFT @KathleenDollard FYI for breaking change documentation |
Fixes #15117
Requires changes to MSBuild in dotnet/msbuild#5994 before this will work.