Skip to content
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

dsplaisted
Copy link
Member

@dsplaisted dsplaisted commented Dec 31, 2020

Fixes #15117

Requires changes to MSBuild in dotnet/msbuild#5994 before this will work.

<UsingTask TaskName="ValidateExecutableReferences" AssemblyFile="$(MicrosoftNETBuildTasksAssembly)" />

<Target Name="ValidateExecutableReferences"
AfterTargets="_GetProjectReferenceTargetFrameworkProperties"
Copy link

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?

Copy link
Member Author

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

Forgind pushed a commit to dotnet/msbuild that referenced this pull request Feb 3, 2021
…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.
@dsplaisted dsplaisted changed the base branch from release/5.0.2xx to release/5.0.3xx February 4, 2021 03:49
@dsplaisted
Copy link
Member Author

/azp run

@dsplaisted dsplaisted marked this pull request as ready for review April 21, 2021 23:57
@azure-pipelines
Copy link

Pull request contains merge conflicts.

@dsplaisted dsplaisted force-pushed the exe-reference-selfcontained-mismatch-error branch from 5cfe1b0 to cc7769c Compare April 22, 2021 05:31
@dsplaisted dsplaisted force-pushed the exe-reference-selfcontained-mismatch-error branch from cc7769c to f8c33dc Compare April 22, 2021 06:55
@dsplaisted dsplaisted merged commit be1e99f into dotnet:release/5.0.3xx Apr 22, 2021
@dsplaisted dsplaisted added the breaking-change Using this label will notify dotnet/compat and trigger a request to file a compat bug label Apr 22, 2021
@dsplaisted
Copy link
Member Author

@marcpopMSFT @KathleenDollard FYI for breaking change documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change Using this label will notify dotnet/compat and trigger a request to file a compat bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants