filipnavara / dotnet-hotrewatch

dotnet watch we always wanted

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

filipnavara opened this issue · comments

watch : 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 Microsoft.DotNet.Watcher.Program.MainInternalAsync(IReporter reporter, CommandLineOptions options, CancellationToken cancellationToken)
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
   at Microsoft.DotNet.Watcher.Program.MainInternalAsync(IReporter reporter, CommandLineOptions options, CancellationToken cancellationToken)
   at Microsoft.DotNet.Watcher.Program.HandleWatch(CommandLineOptions options) in /Users/filipnavara/Projects/dotnet-hotrewatch/dotnet-watch/Program.cs:line 202
watch : An unexpected error occurred

I am aware of this happening for the packages distributed on NuGet. It happens for Release builds of the tool but doesn't seem to happen for Debug builds. I didn't identify the root cause yet.

Workaround is now in place. In case you grabbed a version before the workaround was implemented, you can run:

dotnet tool uninstall -g dotnet-hotrewatch
dotnet tool install -g dotnet-hotrewatch --version "*-*"

On macOS you would need to re-sign the updated version:

codesign -s "-" ~/.dotnet/tools/dotnet-hotrewatch

The root cause of the problem:

#if DEBUG
// In the usual case, use the SDK that contains the dotnet-watch. However during local testing, it's
// much more common to run dotnet-watch from a different SDK. Use the ambient SDK in that case.
MSBuildLocator.RegisterDefaults();
#else
MSBuildLocator.RegisterMSBuildPath(sdkRootDirectory);
#endif

Patches are welcome.

Is what's needed here a "MSBuild finder"? ISTR I have written such a thing in the past, so I can dig out the code for that.

The existing locator code works and it's quite stable. It was hard-coded for release build to assume an installation location within the SDK bundle. The assumption is not true anymore when deployed as global tool.

Simplest solution would be to remove the non-DEBUG lines linked above.

What is not immediately clear is how the tool behaves with global.json file present that forces a non-default SDK version. It's probably worth investigating.