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

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

Open
filipnavara opened this issue Oct 23, 2021 · 4 comments

Comments

@filipnavara
Copy link
Owner

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.

filipnavara added a commit that referenced this issue Oct 23, 2021
filipnavara added a commit that referenced this issue Oct 23, 2021
@filipnavara
Copy link
Owner Author

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

@filipnavara
Copy link
Owner Author

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.

@willdean
Copy link

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.

@filipnavara
Copy link
Owner Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants