1

I have C# application (.NET Framework 4.6.2) with WebApi projects which references System.Runtime.InteropServices.RuntimeInformation (v4.3.0) library through nuget package. See Nuget package reference screen Package was auto-installed as a dependency of 'Microsoft.CodeAnalysis.Razor.2.2.0, Microsoft.DotNet.PlatformAbstractions.2.1.0'

This application was working fine (Builds from my localhost are ok) until I tried to do automatic builds from my teamcity server (different machine). For some reason builds of my app which are provided by teamcity will not start. I get error Could not load file or assembly 'System.Runtime.InteropServices.RuntimeInformation, Version=4.0.2.0...'

So I started to investigate and I found out this:

  • Builds from my localhost (bin/debug) contains lib System.Runtime.InteropServices.RuntimeInformation.dll (File version=4.6.26011.1, Date modified=10.8.2021) --this build works fine
  • Teamcity build contains lib System.Runtime.InteropServices.RuntimeInformation.dll (File version=4.6.24705.1, Date modified=11.5.2016) --this build is not working
  • Nuget package which was downloaded (..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0) on both machines (localhost and teamcity server) contains System.Runtime.InteropServices.RuntimeInformation.dll (File version=4.6.24705.1, Date modified=11.5.2016)

And now I am stuck and literally dont know how to investigate it further. Questions I am asking myself:

  1. How is it possible that my localhost builds contains this reference lib with file version 4.6.26011.1 when in my \packages\ folder this .dll contains file version 4.6.24705.1? Does msbuild maybe take this reference from different location? But from where? I swear I searched my computer and I did not found this library in version 4.6.26011.1 (which is apparently copied to bin/debug by msbuild).
  2. Is there a way to monitor msbuild process and see from where it copies this .dll reference to my bin/debug/ folder on my localhost machine?
  3. How to fix my references so the app runs fine?

21.6.2022 Edit:

Thanks to @mu88 comment I have managed to find out that this library is copied from this location: "C:\Program Files\JetBrains\JetBrains Rider 2021.2.2\tools\MSBuild\Microsoft\Microsoft.NET.Build.Extensions\net462\lib\System.Runtime.InteropServices.RuntimeInformation.dll" to my bin\debug. I have zero ideas why msbuild is using this path for this lib. (This is only library which is copied from this path) --Additional info: I am using some AspNetCore references (e.g Kestrel, ..) so I am targeting .Net Standard 2.0. Could this relate? I am asking because my investigation lead to this issue: ms-build-extensions-file-corrupt-my-bin-web-api-folder. In this issue I have found other links to people having similiar problems like this. I just dont understand the solution there :(

  • I assume on your local machine there is a .NET SDK installed which is missing on TeamCity - hence the newer version of `System.Runtime.InteropServices.RuntimeInformation.dll`. You can increase MSBuild's verbosity with `-verbosity:diag` – mu88 Jun 21 '22 at 11:48
  • @mu88 thanks for your advice. Thanks to -verbosity:diag option I was able to discover that **System.Runtime.InteropServices.RuntimeInformation.dll** (!only this library!) is copied from "C:\Program Files\JetBrains\JetBrains Rider 2021.2.2\tools\MSBuild\Microsoft\Microsoft.NET.Build.Extensions\net462\lib\" on my localhost. I have no idea what Microsoft.NET.Build.Extensions is and why msbuild uses this location to "override" my reference. Any ideas? Additional info: I am using some AspNetCore references (e.g Kestrel, ..) so I am targeting .Net Standard 2.0. – Jan Veselý Jun 21 '22 at 21:19
  • At least we can explain the difference - well done! Could you try to build with VS on your machine? Will it also pick up the assembly from the JetBrains folder? – mu88 Jun 22 '22 at 06:01
  • @mu88 Hey, I just installed VisualStudio 2022 (17.2.5) and I builded my solution. Result is the same as with JB Rider but this time it takes package from *"C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\Microsoft.NET.Build.Extensions\net462\lib\System.Runtime.InteropServices.RuntimeInformation.dll"*. So the .dll is once again overriden by Microsoft.NET.Build.Extensions. I really want to understand why so I created [new stackoverflow issue](https://stackoverflow.com/questions/72742397/what-is-microsoft-net-build-extensions-and-how-does-it-work) – Jan Veselý Jun 24 '22 at 10:11
  • @mu88 So I managed to solve my problem. I had to install **.NET SDK** to **Visual Studio Build Tools 2019** via Visual Studio Installer. Which done "some" magic and it created *MSBuild\Microsoft\Microsoft.NET.Build.Extensions\* folder to my msbuild and now during the build process some System libraries are "overidden" and copied from this new location. So even if I use nuget to download System lib it is actualy useless and this package is not used during the build. I did not manage to find any more info why is it so :( would be nice if someone explained this to me.. – Jan Veselý Jun 29 '22 at 14:09

1 Answers1

1

So I managed to solve my problem. I had to install .NET SDK to Visual Studio Build Tools 2019 via Visual Studio Installer. Which done "some" magic and it created *MSBuild\Microsoft\Microsoft.NET.Build.Extensions* folder to my msbuild and now during the build process some System libraries are "overidden" and copied from this new location. Screenshot

So even if I use nuget to download System lib then this package is not used during the build.

I did not manage to find any more info about the build process :( It would be nice if someone could explain this to me. I created a separate question for this here: What is Microsoft.NET.Build.Extensions and how does it work?.