-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Ensure that tool packages can still publish normally with dotnet publish.
#50445
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
Changes from all commits
11c7c53
cc95d96
af3e647
0a668c8
82cbee2
d802647
8797234
a162f89
ad63e78
66d30f9
1f9e31a
3422187
33bc7e9
6f3fce1
0c3ed3c
2b12e3c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,28 +51,38 @@ NOTE: This file is imported from the following contexts, so be aware when writin | |
| <_UserSpecifiedToolPackageRids Condition="'$(_UserSpecifiedToolPackageRids)' == ''">$(RuntimeIdentifiers)</_UserSpecifiedToolPackageRids> | ||
| <_HasRIDSpecificTools Condition=" '$(_UserSpecifiedToolPackageRids)' != '' ">true</_HasRIDSpecificTools> | ||
| <_HasRIDSpecificTools Condition="'$(_HasRIDSpecificTools)' == ''">false</_HasRIDSpecificTools> | ||
|
|
||
| <!-- NOTE: this line is load-bearing. This impacts Restore behaviors significantly, so we can't prevent the import of these targets _in general_. --> | ||
| <RuntimeIdentifiers Condition="'$(PackAsToolShimRuntimeIdentifiers)' != ''">$(_UserSpecifiedToolPackageRids);$(PackAsToolShimRuntimeIdentifiers)</RuntimeIdentifiers> | ||
|
|
||
| <_IsRidSpecific>false</_IsRidSpecific> | ||
| <_IsRidSpecific Condition="'$(RuntimeIdentifier)' != '' and '$(RuntimeIdentifier)' != 'any'">true</_IsRidSpecific> | ||
|
|
||
| <!-- Not determine information about this specific build of a single (or more!) tool packages --> | ||
| <!-- the publish* properties _can_ be set, but only for the 'inner' RID-specific builds. We need to make sure that for the outer, agnostic build they are unset --> | ||
| <!-- RID information is also stripped during Restore, so we need to make sure user | ||
| decisions are preserved when Restoring, so that publishing-related packages are implicitly included. --> | ||
| <PublishSelfContained Condition="!$(_IsRidSpecific) and '$(MSBuildIsRestoring)' != 'true'">false</PublishSelfContained> | ||
| <!-- Have to set SelfContained similarly because PackTool targets are imported _after_ RuntimeIdentifierInference targets, where the Publish* properties are | ||
| forwarded to the 'base' properties. --> | ||
| <SelfContained Condition="!$(_IsRidSpecific) and '$(MSBuildIsRestoring)' != 'true'">false</SelfContained> | ||
| <PublishTrimmed Condition="!$(_IsRidSpecific) and '$(MSBuildIsRestoring)' != 'true'">false</PublishTrimmed> | ||
| <PublishReadyToRun Condition="!$(_IsRidSpecific) and '$(MSBuildIsRestoring)' != 'true'">false</PublishReadyToRun> | ||
| <PublishSingleFile Condition="!$(_IsRidSpecific) and '$(MSBuildIsRestoring)' != 'true'">false</PublishSingleFile> | ||
|
|
||
| <!-- We need to know if the inner builds are _intended_ to be AOT even if we then explicitly disable AOT for the outer builds. | ||
| Knowing this lets us correctly decide to create the RID-specific inner tools or not when packaging the outer tool. --> | ||
| Knowing this lets us correctly decide to create the RID-specific inner tools or not when packaging the outer tool. --> | ||
| <_InnerToolsPublishAot>false</_InnerToolsPublishAot> | ||
| <_InnerToolsPublishAot Condition="$(_HasRIDSpecificTools) and '$(PublishAot)' == 'true'">true</_InnerToolsPublishAot> | ||
| <PublishAot Condition="!$(_IsRidSpecific) and '$(MSBuildIsRestoring)' != 'true'">false</PublishAot> | ||
|
|
||
| <!-- determining if it's safe to change publish-related properties for this evaluation. We can only override default publishing | ||
| behavior if | ||
| a) we're not restoring (since these flags contain information that influences the assets Restore acquires), and | ||
| b) we are actually packing | ||
| otherwise, we risk altering something that changes downstream behavior for 'normal' publish operations. | ||
| --> | ||
| <_IsImplicitRestore>false</_IsImplicitRestore> | ||
| <_IsImplicitRestore Condition="'$(MSBuildIsRestoring)' == 'true'">true</_IsImplicitRestore> | ||
| <_IsPacking Condition="'$(_IsPacking)' == ''">false</_IsPacking> | ||
|
|
||
| <!-- Now we can set load-bearing properties for the package, but only if the previously-computed conditions hold. | ||
| We must set these to different values for the 'outer' agnostic package, as well as any RID-agnostic child packages, | ||
| so that the Publish of those kinds of packages isn't implicitly coerced to be platform-specific in any way. | ||
| We _do_ have to set both SelfContained and PublishSelfContained here because the logic that applies PublishSelfContained to | ||
| SelfContained has already run. --> | ||
| <PublishSelfContained Condition="!$(_IsRidSpecific) and !$(_IsImplicitRestore) and $(_IsPacking)">false</PublishSelfContained> | ||
| <SelfContained Condition="!$(_IsRidSpecific) and !$(_IsImplicitRestore) and $(_IsPacking)">false</SelfContained> | ||
| <PublishTrimmed Condition="!$(_IsRidSpecific) and !$(_IsImplicitRestore) and $(_IsPacking)">false</PublishTrimmed> | ||
| <PublishReadyToRun Condition="!$(_IsRidSpecific) and !$(_IsImplicitRestore) and $(_IsPacking)">false</PublishReadyToRun> | ||
| <PublishSingleFile Condition="!$(_IsRidSpecific) and !$(_IsImplicitRestore) and $(_IsPacking)">false</PublishSingleFile> | ||
| <PublishAot Condition="!$(_IsRidSpecific) and !$(_IsImplicitRestore) and $(_IsPacking)">false</PublishAot> | ||
|
Comment on lines
+80
to
+85
Member
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. The same condition is repeated here for a bunch of properties. Would it make sense to put these in a separate PropertyGroup with the condition just once on the PropertyGroup? And if we do that it might make sense to avoid creating our own |
||
|
|
||
| <!-- Tool implementation files are not included in the primary package when the tool has RID-specific packages. So only pack the tool implementation | ||
| (and only depend on publish) if there are no RID-specific packages, or if the RuntimeIdentifier is set. --> | ||
|
|
@@ -82,11 +92,13 @@ NOTE: This file is imported from the following contexts, so be aware when writin | |
| <_ToolPackageShouldIncludeImplementation Condition="'$(_ToolPackageShouldIncludeImplementation)' == ''">false</_ToolPackageShouldIncludeImplementation> | ||
|
|
||
| <!-- inner builds and non-RID-specific outer builds need publish content--> | ||
| <_PackToolPublishDependency Condition=" '$(_ToolPackageShouldIncludeImplementation)' != '' and '$(GeneratePackageOnBuild)' != 'true' and $(IsPublishable) == 'true' ">Publish</_PackToolPublishDependency> | ||
| <_PackToolPublishDependency Condition=" $(_ToolPackageShouldIncludeImplementation) and '$(GeneratePackageOnBuild)' != 'true' and $(IsPublishable) == 'true' ">Publish</_PackToolPublishDependency> | ||
|
Member
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. I can't comment the exact line since you didn't change it here, but would it make sense to change this: <_ToolPackageShouldIncludeImplementation Condition=" '$(_ToolPackageShouldIncludeImplementation)' == '' And '$(PackAsTool)' == 'true' And
('$(_UserSpecifiedToolPackageRids)' == ''
or '$(RuntimeIdentifier)' != '')">true</_ToolPackageShouldIncludeImplementation>to this? <_ToolPackageShouldIncludeImplementation Condition=" '$(_ToolPackageShouldIncludeImplementation)' == '' And '$(PackAsTool)' == 'true' And
('$(_HasRIDSpecificTools)' != 'true'
or '$(RuntimeIdentifier)' != '')">true</_ToolPackageShouldIncludeImplementation>Basically use the derived |
||
| <!-- BUT builds that GeneratePackageOnBuild can't directly rely on Publish since Publish would trigger Build, causing an infinite loop. --> | ||
| <!-- To get around this, we try a bit of a workaround: since we can't set NoBuild=true and call Publish that way, we instead trigger all of the | ||
| dependencies of the no-build Publish Target, _PublishNoBuildAlternative --> | ||
| <_PackToolPublishDependency Condition=" '$(_ToolPackageShouldIncludeImplementation)' != '' and '$(GeneratePackageOnBuild)' == 'true' and $(IsPublishable) == 'true' ">$(_PublishNoBuildAlternativeDependsOn)</_PackToolPublishDependency> | ||
| <_PackToolPublishDependency Condition=" $(_ToolPackageShouldIncludeImplementation) and '$(GeneratePackageOnBuild)' == 'true' and $(IsPublishable) == 'true' ">$(_PublishNoBuildAlternativeDependsOn)</_PackToolPublishDependency> | ||
| <!-- No implementation required? Then don't call either target. --> | ||
| <_PackToolPublishDependency Condition="!$(_ToolPackageShouldIncludeImplementation)"></_PackToolPublishDependency> | ||
|
Comment on lines
+95
to
+101
Member
Author
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. these three sets were actually a big part of the problem - they were incorrectly checking |
||
|
|
||
| <!-- GenerateNuspec is called in two places: crossTargeting NuGet targets, and single-targeting NuGet targets. | ||
| Tools need to ensure that | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -121,6 +121,7 @@ Copyright (c) .NET Foundation. All rights reserved. | |
| <PreferNativeArm64 Condition="'$(PreferNativeArm64)'==''">false</PreferNativeArm64> | ||
| <SignAssembly Condition="'$(SignAssembly)'==''">false</SignAssembly> | ||
| <DelaySign Condition="'$(DelaySign)'==''">false</DelaySign> | ||
| <!-- TODO: should we set _IsPacking=true on the NuGet Pack targets when they hook up the 'generate package on build' stuff --> | ||
|
Member
Author
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. @dsplaisted / @zivkan I think this is potentially a thing that we should dig into. Here's the relevant part of the Pack Targets: <Target Name="_PackAsBuildAfterTarget"
AfterTargets="Build"
Condition="'$(GeneratePackageOnBuild)' == 'true' AND '$(IsInnerBuild)' != 'true'"
DependsOnTargets="Pack">
</Target>
<Target Name="_CleanPackageFiles"
DependsOnTargets="_GetOutputItemsFromPack"
AfterTargets="Clean"
Condition="'$(GeneratePackageOnBuild)' == 'true' AND '$(IsInnerBuild)' != 'true'">
<ItemGroup>
<_PackageFilesToDelete Include="@(_OutputPackItems)"/>
</ItemGroup>
<Delete Files="@(_PackageFilesToDelete)"/>
</Target>It sucks to keep propagating
Member
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. I don't think we can successfully set |
||
| <GeneratePackageOnBuild Condition="'$(GeneratePackageOnBuild)'==''">false</GeneratePackageOnBuild> | ||
| <PackageRequireLicenseAcceptance Condition="'$(PackageRequireLicenseAcceptance)'==''">false</PackageRequireLicenseAcceptance> | ||
| <DebugSymbols Condition="'$(DebugSymbols)'==''">false</DebugSymbols> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,14 +29,17 @@ public void It_builds_the_project_successfully_with_static_graph_and_isolation() | |
| public void It_cleans_the_project_successfully_with_static_graph_and_isolation() | ||
| { | ||
| var (testAsset, outputDirectories) = BuildAppWithTransitiveDependenciesAndTransitiveCompileReference(new[] { "/graph", "/bl:build-{}.binlog" }); | ||
| var binlogDestPath = Environment.GetEnvironmentVariable("HELIX_WORKITEM_UPLOAD_ROOT") is { } ciOutputRoot && Environment.GetEnvironmentVariable("HELIX_WORKITEM_ID") is { } helixGuid ? | ||
| Path.Combine(ciOutputRoot, "binlog", helixGuid, $"{nameof(It_cleans_the_project_successfully_with_static_graph_and_isolation)}.binlog") : | ||
| "./msbuild.binlog"; | ||
|
Comment on lines
+32
to
+34
Member
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. I think this can be removed in favor of the logic that's now built in to |
||
|
|
||
| var cleanCommand = new DotnetCommand( | ||
| Log, | ||
| "msbuild", | ||
| Path.Combine(testAsset.TestRoot, "1", "1.csproj"), | ||
| "/t:clean", | ||
| "/graph", | ||
| "/bl:clean-{}.binlog"); | ||
| $"/bl:{binlogDestPath}"); | ||
|
|
||
| cleanCommand | ||
| .Execute() | ||
|
|
@@ -175,12 +178,16 @@ public void It_builds_the_project_successfully_when_RAR_does_not_find_all_refere | |
| private (CommandResult BuildResult, IReadOnlyDictionary<string, DirectoryInfo> OutputDirectories) Build( | ||
| TestAsset testAsset, | ||
| IEnumerable<string> targetFrameworks, | ||
| string[] msbuildArguments | ||
| string[] msbuildArguments, | ||
| [CallerMemberName] string callingMethod = "" | ||
| ) | ||
| { | ||
| var buildCommand = new BuildCommand(testAsset, "1"); | ||
| buildCommand.WithWorkingDirectory(testAsset.TestRoot); | ||
| var buildResult = buildCommand.ExecuteWithoutRestore(msbuildArguments); | ||
| var binlogDestPath = Environment.GetEnvironmentVariable("HELIX_WORKITEM_UPLOAD_ROOT") is { } ciOutputRoot && Environment.GetEnvironmentVariable("HELIX_WORKITEM_ID") is { } helixGuid ? | ||
| Path.Combine(ciOutputRoot, "binlog", helixGuid, $"{callingMethod}.binlog") : | ||
| "./msbuild.binlog"; | ||
| var buildResult = buildCommand.ExecuteWithoutRestore([..msbuildArguments, $"/bl:{binlogDestPath}"]); | ||
|
|
||
| var outputDirectories = targetFrameworks.ToImmutableDictionary(tf => tf, tf => buildCommand.GetOutputDirectory(tf)); | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.