-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 won't publish self contained exe without a RuntimeIdentifier. I am passing -r in the command. #10566
Comments
Alright so just figured something out. My project setup is The Gui app references the command line app to call some code directly I guess it is not passing -r to the command line app. If I manually change the csproj files for both and specify the same runtime it works. But I want to build this for all Windows, Linux, Mac its kind of a pain, to edit both each time. |
Same issue. Edit: Can be fixed by going to the linked projects .csproj file and adding a RuntimeIdentifiers tag with all the platforms you are releasing for:
To be honest, I'm not sure if this even is a bug, but it's a useless error message that doesn't help me resolve the problem, and probably won't help others aside from finding this git issue. |
There are two ways to work around this:
<ItemGroup>
<ProjectReference Include="..\TestCons\TestCons.csproj" GlobalPropertiesToRemove="SelfContained" />
</ItemGroup> |
I think you ran into this issue: #10902 which is still open at the time of writing. In my case I could implement a workaround as @neobenedict suggested which really not ideal. |
This error is kind of silly. If you just drop the |
- Workaround for .NET bug dotnet/sdk#10566, dotnet/sdk#10902
Interestingly, passing |
In addition to @dasMulli's workaround, I also needed to add |
Dropping the
|
not sure if --no-self-contained is the right flag but dotnet/sdk#10566 prevents using --self-contained true even if it were the right one.
Hit the same issue. I've a .NET 6 project with tests that reference ASP.NET Core Web app. The tests refuse to build with |
I'm also now struggling with this as I added The error doesn't seem to help much either as one of the errors points to a project defined as the following which doesn't make sense since it's not an executable: <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<IsPackable>false</IsPackable>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Zio" Version="0.9.1" />
</ItemGroup>
</Project> |
Specifying I dumped binlogs for affected project and the main difference is that |
Here is the kludge for CI that I'm going to use for now 🦨...
<Project>
<PropertyGroup Condition=" '$(TF_BUILD)' != '' AND '$(DOTNET_RUNTIME_IDENTIFIER)' != '' ">
<RuntimeIdentifier>$(DOTNET_RUNTIME_IDENTIFIER)</RuntimeIdentifier>
</PropertyGroup>
<PropertyGroup Condition=" '$(TF_BUILD)' != '' AND '$(DOTNET_SELF_CONTAINED)' != '' ">
<SelfContained>$(DOTNET_SELF_CONTAINED)</SelfContained>
</PropertyGroup>
</Project>
- task: DotNetCoreCLI@2
displayName: '.NET | Build'
inputs:
command: 'build'
projects: '**/*.csproj'
arguments: >-
--configuration Release
--runtime debian-x64
--self-contained
env:
DOTNET_RUNTIME_IDENTIFIER: 'debian-x64'
DOTNET_SELF_CONTAINED: 'True' |
Hello there, I still issue this problem with .NET6 // in the file: ./src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets:
<NETSdkWarning Condition="'$(_SelfContainedWasSpecified)' != 'true' and
'$(_CommandLineDefinedRuntimeIdentifier)' == 'true' and
'$(TargetFrameworkIdentifier)' == '.NETCoreApp' and
'$([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '6.0'))"
ResourceName="SelfContainedOptionShouldBeUsedWithRuntime" /> So it might be related to the fact that // in the file: ./src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.RuntimeIdentifierInference.targets
// But this is only to avoid breaking changes from 1.0 behavior.
<_SelfContainedWasSpecified Condition="'$(SelfContained)' != ''">true</_SelfContainedWasSpecified>
<SelfContained Condition="'$(SelfContained)' == '' and '$(RuntimeIdentifier)' != ''">true</SelfContained>
<SelfContained Condition="'$(SelfContained)' == ''">false</SelfContained> So, then into the option parser, I couldn't see where the issue is. Which looks good to me: var selfContainedSpecified = parseResult.HasOption(SelfContainedOption) || parseResult.HasOption(NoSelfContainedOption); So, I don't know where to search more. |
TWIMCBasically, I gave up and just patch # Patch Microsoft.Common.CurrentVersion.targets in all installed 6.x SDKs
& 'dotnet' @('--list-sdks') |
Select-String -Pattern '(6\.\d+\.\d+).+?\[(.+?)\]' -AllMatches |
ForEach-Object { Join-Path $_.Matches.Groups[2].Value $_.Matches.Groups[1].Value } |
Where-Object { Test-Path -LiteralPath $_ -PathType Container } |
Join-Path -ChildPath 'Microsoft.Common.CurrentVersion.targets' |
Where-Object { Test-Path -LiteralPath $_ -PathType Leaf } |
ForEach-Object {
# Fail fast
try {
[xml]$xml = [System.IO.File]::ReadAllText($_)
$nsm = [System.Xml.XmlNamespaceManager]::new($xml.NameTable)
$nsm.AddNamespace('ns', $xml.Project.xmlns)
$n = $xml.xSelectSingleNode(
"/ns:Project/ns:Target[@Name='GetTargetFrameworks']/ns:ItemGroup/ns:_ThisProjectBuildMetadata/ns:IsRidAgnostic/@Condition",
$nsm
)
# Add check for for _CommandLineDefinedRuntimeIdentifier
# https://github.com/dotnet/msbuild/pull/6924#issuecomment-978128930
$n.'#text' = ' {0} ' -f @'
'$(RuntimeIdentifier)' == '' and '$(RuntimeIdentifiers)' == '' and $(_CommandLineDefinedRuntimeIdentifier) == ''
'@
$xml.Save($_)
}
finally {}
} |
I'm having the same problem. Running I should note that the project in question gets successfully published anyway. |
This was the solution for me. Just add |
We believe this has been fixed at this point as the original issue was from 2019. If it's still broken in 7.0.100, please file a new issue. |
Confirmation: |
Is the fix backported to .NET 6 ? Not everyone can use .NET 7 yet. |
Steps to reproduce
Run the following command
dotnet publish --self-contained true -f netcoreapp3.0 -r linux-x64
Expected behavior
Should publish a single executable file for the given runtime
Actual behavior
C:\Program Files\dotnet\sdk\3.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.RuntimeIdentifierInference.targets(127,5): error NETSDK1031: It is not supported to build or publish a self-contained application without specifying a RuntimeIdentifier. Please either specify a RuntimeIdentifier or set SelfContained to false. [C:\Users\ardsafa\Documents\git\fdere\fdere\fdere\fdere.csproj]
Environment data
.NET Core SDK (reflecting any global.json): Version: 3.0.100
Commit: 04339c3
Runtime Environment:
OS Name: Windows
OS Version: 10.0.18362
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\3.0.100\
Host (useful for support):
Version: 3.0.0
Commit: 7d57652f33
.NET Core SDKs installed:
2.1.700 [C:\Program Files\dotnet\sdk]
2.2.300 [C:\Program Files\dotnet\sdk]
3.0.100-rc1-014190 [C:\Program Files\dotnet\sdk]
3.0.100 [C:\Program Files\dotnet\sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.0-rc1.19457.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.0-rc1-19456-20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.0.0-rc1-19456-20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
The text was updated successfully, but these errors were encountered: