0

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?

Shahin Dohan
  • 6,149
  • 3
  • 41
  • 58

1 Answers1

1

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.

Martin Ullrich
  • 94,744
  • 25
  • 252
  • 217
  • Thanks Martin! The reason I needed this was to install a RID-specific nuget package (IBM DB2 EF Core) in a dependent project when building the main project. I achieved it like this: https://stackoverflow.com/a/63854732/1469494 – Shahin Dohan Oct 20 '20 at 07:05
  • If only I knew where this RID are defined. I never did it. They are just there. So if I should not define the: Where can I delete them. I can't even search for them because I don't know what they look like. #MavenDidItRight – Martin Dec 06 '21 at 13:52