sdk: Cannot publish self-contained worker project referencing another
When trying to publish single file exe for worker projects get error runtime identifier is required, but it was!
This happens when referencing another core 3 console project.
$ dotnet publish -r linux-x64 -c Release --self-contained true
Microsoft (R) Build Engine version 16.3.0+0f4c62fea for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Restore completed in 102.79 ms for C:\Dev\magnet-filewatcher\src\watcher\watcher.csproj.
Restore completed in 102.79 ms for C:\Dev\magnet-filewatcher\src\worker\worker.csproj.
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:\Dev\magnet-filewatcher\src\watcher\watcher.csproj]
Steps to reproduce
- Create new worker project with
dotnet new worker - Add reference to your another core 3.0 console project with
dotnet add reference .NET Core SDK (3.0.100)- Windows 10 X64 es).
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 34
- Comments: 20 (2 by maintainers)
Commits related to this issue
- Merge pull request #17 from microsoft/user/miscovet/build Update build config due to dotnet/sdk#10902 — committed to microsoft/OSSGadget by scovetta 4 years ago
- 🪥 Specify `RuntimeIdentifiers` in project file as a workaround - Workaround for .NET bug dotnet/sdk#10566, dotnet/sdk#10902 — committed to database64128/shadowsocks-uri-generator by database64128 3 years ago
- Add runtime ids because of https://github.com/dotnet/sdk/issues/10902 — committed to wareismymind/peer by deleted user 3 years ago
- Release: Removed the '--self-contained true' flag as that is the default if the '--runtime' flag is specified and the github issue (https://github.com/dotnet/sdk/issues/10902) suggested doing it. — committed to silvera/commandir by silvera a year ago
This is still happening in .NET 5. Any fixes? Specifying the RuntimeIdentifier in the .csproj file is NOT a solution because if you develop on Windows, then deploy for Linux, you’ll need to have two .csproj files for each OS, NOT GOOD.
I had the same problem with NetCore 3.1
This was not working:
Fixed by removing
--self-contained true(that is the default anyway)I found one can get around the error by specifying
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>in the.csprojin both the worker and referenced console project…You can specify multiple targets like so:
<RuntimeIdentifiers>win-x64;osx-x64;linux-x64</RuntimeIdentifiers>as per the docs "Multiple RIDs can be defined as a semicolon-delimited list in the project file’s <RuntimeIdentifiers> element. "
This is also happening to me when creating a self-contained console that references another console. Having
<RuntimeIdentifier>win-x64</RuntimeIdentifier>in both .csproj gets around the issue though@darkguy2008 property groups support conditions:
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">Still not a fix but better than having multiple files. Reference is in: https://docs.microsoft.com/en-us/visualstudio/msbuild/propertygroup-element-msbuild?view=vs-2019 and https://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild-conditional-constructs?view=vs-2019I have a similar/related issue, when i build for linux (Docker/Linux/Raspberry) I get:
ld not load file or assembly ‘LibUsbDotNet, Version=3.0.0.0, Culture=neutral, PublicKeyToken=c677239abe1e02a9’. The system cannot find the file specified. Also notice for linux it doesn’t emit the libusbdotnet.dll,
Tip for @darkguy2008 - you can put variables into your build so you can use 1 project file.
The various combinations of
--runtimeand--self-containedw/ and without<PropertyGroup> <RuntimeIdentifier>win-x64</RuntimeIdentifier> </PropertyGroup>is all very confusing.@gimmi 's suggestion worked for me. Thanks!