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

dotnet publish --self-contained can't handle build-time references #24434

Open
jhudsoncedaron opened this issue Mar 17, 2022 · 3 comments
Open

Comments

@jhudsoncedaron
Copy link

jhudsoncedaron commented Mar 17, 2022

Describe the bug

Regression from .NET 5

dotnet publish always wants --self-contained or --no-self-contained now and blows up on Any RID references because of it.

To Reproduce

Project file fragment that breaks

  <ItemGroup>
    <ProjectReference Include="..\Cedaron.Build.CreateAssemblyInfo\Cedaron.Build.CreateAssemblyInfo.csproj" Properties="RuntimeIdentifier=">
      <Private>false</Private>
      <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
      <SkipGetTargetFrameworkProperties>true</SkipGetTargetFrameworkProperties>
      <ExcludeAssets>all</ExcludeAssets>
    </ProjectReference>
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\Cedaron.Build.GenerateDataObjects\Cedaron.Build.GenerateDataObjects.csproj" Properties="RuntimeIdentifier=">
      <Private>false</Private>
      <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
      <SkipGetTargetFrameworkProperties>true</SkipGetTargetFrameworkProperties>
      <ExcludeAssets>all</ExcludeAssets>
    </ProjectReference>
  </ItemGroup>

  <Target Name="PrecompileScript" BeforeTargets="BeforeCompile">
    <Exec Command="dotnet run -c $(Configuration) --no-build --project ..\Cedaron.Build.GenerateDataObjects\Cedaron.Build.GenerateDataObjects.csproj -- -r -o PodObjects.cs schema.txt GeneratePodObjects" />
  </Target>

These are a build-tool dependencies. They should not (and are not--we excluded it when we pick up from "package") be shipped; furthermore, changing to the Any RID is correct (otherwise cross compilation won't work at all), and furthermore they must not build self-contained.

I cannot omit the <ProjectReference> entries or the build becomes unstable. It is absolutely necessary that the top-level build be able to resolve dependencies once and build once; otherwise the build will crash periodically with two copies of dotnet run trying to write to the bin or obj directories at once.

Exceptions (if any)

C:\Program Files\dotnet\sdk\6.0.201\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.RuntimeIdentifierInference.targets(150,5): error NETSDK1031: It is not supported to build or publish a self-contained application without specifying a RuntimeIdentifier. You must either specify a RuntimeIdentifier or set SelfContained to false. [C:\Users\jhudson\dev\cento_forms2\src\Cedaron.Build.CreateAssemblyInfo\Cedaron.Build.CreateAssemblyInfo.csproj]
C:\Program Files\dotnet\sdk\6.0.201\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.RuntimeIdentifierInference.targets(150,5): error NETSDK1031: It is not supported to build or publish a self-contained application without specifying a RuntimeIdentifier. You must either specify a RuntimeIdentifier or set SelfContained to false. [C:\Users\jhudson\dev\cento_forms2\src\Cedaron.Build.GenerateDataObjects\Cedaron.Build.GenerateDataObjects.csproj]

Further technical details

.NET SDK (reflecting any global.json):
Version: 6.0.201
Commit: ef40e6a

Runtime Environment:
OS Name: Windows
OS Version: 10.0.19044
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\6.0.201\

Host (useful for support):
Version: 6.0.3
Commit: c24d9a9c91

@jhudsoncedaron
Copy link
Author

jhudsoncedaron commented Mar 22, 2022

Demonstration sample
net6refchain.zip

It builds just fine but when you run dotnet publish -r win7-x64, nope!

But change everything to .net 5 and there's no problem.
net5refchain.zip

@jhudsoncedaron
Copy link
Author

In other news, it seems the actual reproduction command has gotten lost. It is cd Exe ; dotnet publish -r win7-x64 --self-contained

@jhudsoncedaron
Copy link
Author

So I've tried to chance this error to its source and found some stuff.

  1. The test for Self Contained that raises NETSDK1179 is wrong.
    <NETSdkWarning Condition="'$(_SelfContainedWasSpecified)' != 'true' and
                   '$(_CommandLineDefinedRuntimeIdentifier)' == 'true' and
                   '$(TargetFrameworkIdentifier)' == '.NETCoreApp' and
                   $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '6.0'))"
               ResourceName="SelfContainedOptionShouldBeUsedWithRuntime" />

But _SelfContainedWasSpecified is merely

    <!-- Detecting property presence is not harmful and can be done in an unconditioned way -->
    <_SelfContainedWasSpecified Condition="'$(SelfContained)' != ''">true</_SelfContainedWasSpecified>

thus causing even an explicit framework dependent project to raise 1179.

The actual error happens at

    <NETSdkError Condition="'$(SelfContained)' == 'true' and '$(RuntimeIdentifier)' == ''"
                 ResourceName="CannotHaveSelfContainedWithoutRuntimeIdentifier" />

which means that SelfContained propagated down the dependent references.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant