I have a simple prebuild target in a dependent project (called DAL):
<Target Name="PreBuild" BeforeTargets="Build">
<Message Text="RuntimeIdentifier value is: $(RuntimeIdentifier)" Importance="high" />
</Target>
When I build DAL, everything works as expected:
Command: dotnet build DAL\DAL.csproj --runtime linux-x64
Output: RuntimeIdentifier value is: linux-x64
But when I build the project that references DAL, the value for RuntimeIdentifier
disappears:
Command: dotnet build Transformer\Transformer.csproj --runtime linux-x64
Output: RuntimeIdentifier value is:
I added the --verbosity d
switch to the build command, and I noticed this:
Removing Properties for project "..\DAL\DAL.csproj":
TargetFramework
RuntimeIdentifier
Why is msbuild doing this and how can I pass the RuntimeIdentifier information to the DAL project when building/publishing the main project?
.NET Core SDK version: 3.1.402
, all projets target .NET Core 3.1
Thanks!
UPDATE: I added the following element to my csproj files:
<RuntimeIdentifiers>win-x64;linux-x64</RuntimeIdentifiers>
Now the output is:
Determining projects to restore...
All projects are up-to-date for restore.
DAL -> C:\Source\...\DAL\bin\Debug\netcoreapp3.1\linux-x64\DAL.dll
RuntimeIdentifier value is: linux-x64
DAL -> C:\Source\...\DAL\bin\Debug\netcoreapp3.1\DAL.dll
RuntimeIdentifier value is:
Core -> C:\Source\...\Core\bin\Debug\netcoreapp3.1\Core.dll
Transformer -> C:\Source\...\Transformer\bin\Debug\netcoreapp3.1\linux-x64\Transformer.dll
It seems like the workaround is to set the RuntimeIdentifiers
element, is this by design?
This is by design. Runtime Identifiers are more a concern of the entry point application project(s) that will be published, not the library projects.
Previously (1.0 / preview timeframe), the RID (Runtime IDentifier) was forwarded and caused a lot of rebuilds and NuGet inconsistencies with the way the 1.0/1.1 runtime NuGet packages were constructed.
Currently the best way to distribute RID-specific assemblies is building a NuGet packge with the assemblies placed in the right architecture specific folder.
However, it is also possible to design runtime code that checks RuntimeInformation.IsOSPlatform(OSPlatform.***)
to choose the right APIs to work with or the right assemblies to load.