When trying to build System.Runtime.Tests inside VS you would get the following error:
C:\Users\prgovi\.nuget\packages\microsoft.net.sdk.il\5.0.0-preview.4.20202.18\targets\Microsoft.NET.Sdk.IL.Common.targets(12,60): error MSB4226: The imported project "C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Microsoft.Common.CrossTargeting.targets" was not found. Also, tried to find "Microsoft.Common.CrossTargeting.targets" in the fallback search path(s) for $(MSBuildExtensionsPath) - "C:\Program Files (x86)\MSBuild" . These search paths are defined in "C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Current\Bin\MSBuild.exe.Config". Confirm that the path in the <Import> declaration is correct, and that the file exists on disk in one of the search paths.
I took a look we're trying to import Microsoft.Common.CrossTargeting.targets from $(MSBuildExtensionsPath) which in DesignTimeBuild seems to not evaluate to the location where these targets are:
https://github.com/dotnet/runtime/blob/77a383275f1f5dc062a113102856718fe6e8b2ab/src/coreclr/src/.nuget/Microsoft.NET.Sdk.IL/targets/Microsoft.NET.Sdk.IL.Common.targets#L12
Changing it to $(MSBuildToolsPath) fixes the issue and works on both command line and DesignTimeBuild.
Once that is fixed, then you would get an error:
C:\Users\prgovi\.nuget\packages\microsoft.net.sdk.il\5.0.0-preview.4.20202.18\targets\Microsoft.NET.Sdk.IL.targets(62,5): error : Package runtime.win-x86.microsoft.netcore.ilasm\5.0.0-preview.4.20202.18 was not restored
we're using <_OSArchitecture>$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)</_OSArchitecture> to calculate the arch and the path of the ilasm and ildasm packages, but in DesignTimeBuild it seems to evaluate to x86 even in a x64 machine.
cc: @ViktorHofer @Anipik @ericstj
Can you please submit a PR for 1)? If my memory serves me right 2) is expected as VS is x86. I think ericstj and I talked about that.
cc @eerhardt for the second issue.
Can you please submit a PR for 1)
Yeah I was planning on doing that just wanted to discuss first. Tomorrow I鈥檒l put it up.
2) is expected as VS is x86. I think ericstj and I talked about that.
Yeah I thought about that. Should we rely on something else when in DesignTimeBuild?
Yeah I thought about that. Should we rely on something else when in DesignTimeBuild?
Does this logic need to run during design time build?
2) is expected as VS is x86
This is not expected (at least to me). The line of code above is $([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture) - i.e. the Operating System's architecture. This shouldn't change in a design-time build. It should always be the same thing on the same machine regardless of the process.
My guess is that something else is writing to the $(_OSArchitecture) property and upsetting this code.
EDIT: or it could be someone is writing to the $(MicrosoftNetCoreIlasmPackageRuntimeId) property. Notice it doesn't use $(_OSArchitecture) if it is already set.
Interesting find @eerhardt -- it seems like we set ToolRuntimeID to x64 when building inside visual studio, or at least that's what we intend: https://github.com/dotnet/runtime/blob/a1f86575ac262fc89b00399ad4fc3c8a73b90cb4/src/libraries/Directory.Build.props#L108
I think the next step would be to get a binlog of the design-time build, and find out where the x86 is coming from.
Yeah, that is what I'm doing now... maybe if we're at design-time build we shouldn't be setting MicrosoftNetCoreIlasmPackageRuntimeId at all.
So the value is coming from HostArch: https://github.com/dotnet/runtime/blob/a1f86575ac262fc89b00399ad4fc3c8a73b90cb4/src/libraries/Directory.Build.props#L37
which uses ProcessArchitecture instead of OSArchitecture -- I guess that was intentional for cross builds in docker.
and it seems like we had a typo when checking if ToolRuntimeRID was empty and compared to ToolRuntimeID:
https://github.com/dotnet/runtime/blob/a1f86575ac262fc89b00399ad4fc3c8a73b90cb4/src/libraries/Directory.Build.props#L109
So that is always overriding the value to use the HostArch.
@safern should this be closed now?
Nope, still need to update the IL.SDK -- will do that now. Thanks for the ping.
Most helpful comment
So the value is coming from
HostArch: https://github.com/dotnet/runtime/blob/a1f86575ac262fc89b00399ad4fc3c8a73b90cb4/src/libraries/Directory.Build.props#L37which uses
ProcessArchitectureinstead ofOSArchitecture-- I guess that was intentional for cross builds in docker.and it seems like we had a typo when checking if
ToolRuntimeRIDwas empty and compared toToolRuntimeID:https://github.com/dotnet/runtime/blob/a1f86575ac262fc89b00399ad4fc3c8a73b90cb4/src/libraries/Directory.Build.props#L109
So that is always overriding the value to use the
HostArch.