try-convert icon indicating copy to clipboard operation
try-convert copied to clipboard

System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Build, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

Open sqeezy opened this issue 4 years ago • 5 comments

After watching the .Net Conf demo I tried to convert a medium sized solution containing a WPF app and some libraries and unit test projects. The projects are .Net-Framework 4.7.2.

dotnet --version
5.0.100

dotnet tool list -g
Package Id                              Version          Commands
----------------------------------------------------------------------------
apiport                                 2.8.14           ApiPort
try-convert                             0.7.157502       try-convert

When running try-convert -w [solution_name] I got the following error:

System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Build, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
File name: 'Microsoft.Build, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
   at MSBuild.Abstractions.MSBuildConversionWorkspaceLoader.LoadWorkspace(String path, Boolean noBackup, String tfm, Boolean keepCurrentTFMs, Boolean forceWeb)
   at MSBuild.Conversion.Program.Run(String project, String workspace, String msbuildPath, String tfm, Boolean forceWebConversion, Boolean preview, Boolean diffOnly, Boolean noBackup, Boolean keepCurrentTfms) in /_/src/try-convert/Program.cs:line 103

Thanks for the effort of creating this tool 👍 Regards, Anton

sqeezy avatar Dec 03 '20 08:12 sqeezy

Hey @sqeezy can you verify that this still happens with the latest version of the tool?

The error would indicate that you don't have an appropriate MSBuild installed. Is Visual Studio installed on your machine? If not, it also is likely required to install.

cartermp avatar Dec 09 '20 02:12 cartermp

Version 0.7.157502 seems to be the latest version of the tool. At least I could not find a newer one even with adding --prerelease while searching. The machine I'm trying this on has multiple versions MSBuild installed. I updated Visual Studio and Visual Studio Buildtools to 16.8.3 and still get the same error.

sqeezy avatar Dec 09 '20 07:12 sqeezy

would you happen to know if the project you're converting specifies a specific version of an msbuild toolset? e.g. like this https://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild-toolset-toolsversion?view=vs-2019

If so, what happens if you remove it?

cartermp avatar Dec 15 '20 16:12 cartermp

I removed all the toolset version entries from csproj-files. The same error message was shown afterwards.

sqeezy avatar Dec 15 '20 16:12 sqeezy

If you are running in a developer prompt, try-convert apparently fails to find MSBuild. The solution for me was to specify the path directly using -m "C:\Program Files\dotnet\sdk\5.0.201 (your SDK path may be different).

snorrk avatar Mar 30 '21 21:03 snorrk