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

RuntimeIdentifier is not correctly populated when not supplied #43356

Closed
leppie opened this issue Sep 11, 2024 · 2 comments
Closed

RuntimeIdentifier is not correctly populated when not supplied #43356

leppie opened this issue Sep 11, 2024 · 2 comments
Labels
Area-NetSDK needs team triage Requires a full team discussion untriaged Request triage from a team member

Comments

@leppie
Copy link

leppie commented Sep 11, 2024

Something has changed drastically with msbuild.

From #43339 /cc @rainersigwald

Update 3:

Looking further, it seems it is the way that Microsoft.NETCore.ILAsm and Microsoft.NETCore.ILDAsm is packaged.

Closing as I dont think anything not working as expected.

Update 2:

Starting to think something was actually fixed in the latest release and I was basing my assumptions off buggy code. The 'solution' (to my problem) with UseCurrentRuntimeIdentifier works correctly under .NET 8 SDK too.

My actual issue is that I need ILASM/ILDASM during build time. But the final output is targetted for anycpu. The problem is that PackageReference assumes runtime target and not build time target.

Is there some analoguous PackageReference for build time? Like NodeJS devDependencies?

Update:

Everything works as previously if you add -p:RuntimeIdentifier=win-x64 even the .NET 2 issue is not present. So it seems it does not pick this up automatically anymore like it did. Edit: for .NET 2/4 this is incorrectly detected as win-x86. For .NET 9, the default is blank.

Testing repo: https://github.com/IronScheme/appveyor-test/tree/main

Orignal follows:

Worked yesterday before installing RC1 / updating VS2022 Preview.

Example project

<Project Sdk="Microsoft.NET.Sdk" DefaultTargets="Rebuild">
  
  <!-- 
  Program.cs

  System.Console.WriteLine("Hello, World!");
  -->

  <PropertyGroup>
    <TargetFrameworks>net2.0;net4.0;net9.0</TargetFrameworks>
    <OutputType>Exe</OutputType>
    <LangVersion>9.0</LangVersion>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.NETCore.ILAsm" Version="9.0.0-rc.1.24431.7" />
    <PackageReference Include="Microsoft.NETCore.ILDAsm" Version="9.0.0-rc.1.24431.7" />
  </ItemGroup>

  <Target Name="PostBuild" AfterTargets="PostBuildEvent">
      <PropertyGroup>
        <ILAsmPath>"$(TargetDir)ilasm" /dll /NOLOGO /QUIET "$(TargetDir)$(TargetName).res"</ILAsmPath>
        <ILDAsmPath>"$(TargetDir)ildasm" /LINENUM</ILDAsmPath>
        <ILAsmArgs>/out:"$(TargetDir)$(TargetName).dll" "$(TargetDir)$(TargetName).il"</ILAsmArgs>
        <ILDAsmArgs>/out:"$(TargetDir)$(TargetName).il" "$(TargetPath)"</ILDAsmArgs>
      </PropertyGroup>

      <Message Importance="High" Text="RuntimeIdentifier/Platform/Framework: $(RuntimeIdentifier) / $(Platform) / $(TargetFramework)"></Message>
      <Message Importance="High" Text="ILAsm: $(ILAsmPath) $(ILAsmArgs)"></Message>
      <Message Importance="High" Text="ILDAsm: $(ILDAsmPath) $(ILDAsmArgs)"></Message>

      <Exec Command="dir /b $(TargetDir)"/>
      <Exec Command="$(ILDAsmPath) $(ILDAsmArgs)"/>
      <Exec Command="$(ILAsmPath) $(ILAsmArgs)" />
  </Target>

</Project>

Invoke options:

  • dotnet build -restore -tl:off -v:m --maxcpucount:1
  • dotnet msbuild -restore -tl:off -v:m --maxcpucount:1
  • msbuild -restore -tl:off -v:m --maxcpucount:1

.NET 2 and .NET 4 targets work in all cases.

NET 9.0 fails all cases. Packages (ilasm/ildasm) not present in output dir.

.NET 9.0 works when adding --ucr with dotnet build . Others dont accept this option.

.NET 2 target copies native framework libs to output dir when using msbuild .

Also tested with previous .NET Core targets, all fail the same.

I suspect something is fishy with platform and/or PackageReference.

@leppie
Copy link
Author

leppie commented Sep 12, 2024

I have had some success doing this now while having <PlatformTarget>anycpu</PlatformTarget>.

  <Target Name="SetRID" BeforeTargets="CollectPackageReferences">
    <PropertyGroup>
      <RuntimeIdentifier>win-x64</RuntimeIdentifier>
    </PropertyGroup>
  </Target>

   <Target Name="ClearRID" BeforeTargets="PreBuildEvent">
    <PropertyGroup>
      <RuntimeIdentifier></RuntimeIdentifier>
    </PropertyGroup>
  </Target>

Unfortunately this is not portable, but will look for a solution.

@leppie
Copy link
Author

leppie commented Sep 12, 2024

This seems like a portable option

<UseCurrentRuntimeIdentifier>true</UseCurrentRuntimeIdentifier>

and just

   <Target Name="ClearRID" BeforeTargets="PreBuildEvent">
    <PropertyGroup>
      <RuntimeIdentifier></RuntimeIdentifier>
    </PropertyGroup>
  </Target>

@leppie leppie closed this as completed Sep 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-NetSDK needs team triage Requires a full team discussion untriaged Request triage from a team member
Projects
None yet
Development

No branches or pull requests

2 participants