-
Notifications
You must be signed in to change notification settings - Fork 87
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
Should MSBuildLocator handle loading of NuGet assemblies? #86
Comments
Yes, this should be built into Locator. The MSBuild-NuGet relationship is only getting closer over time; we should treat it as part of MSBuild in this context. |
@rainersigwald We are running into the same issue here. A fix for this would really be awesome! |
In dotnet/msbuild#5241, @zivkan notest that this fails only on Core, which is extra funky. I'll sync with @microsoft/msbuild-maintainers on scheduling this in the next sprint planning (late this week? I think). |
Doesn't this problem generalize to more than just nuget? Wouldn't any dll that MSBuild redistributes also need handling in locator? Or, even more generally, any dll that MSBuild loads and isn't part of some standard BCL path probing path, needs handling in the locator? dotnet dll loading and probing logic was always a big confusing mess to me. :) |
I think that's true, but the nuget dlls are highly likely to have breaking changes between versions 😆. Something like JSON.NET (for example) doesn't typically make binary breaking changes so it's less crucial to use the exact version that MSBuild ships. |
I've now also encountered the same issue with |
For Core, we should think about having a universal fallback to next-to-MSBuild. That would catch a bunch of SDK-delivered stuff. However
I don't see this disassembling LibGit2Sharp 0.25.0.0 that comes with NBGV 2.2.13. How did you figure that out? |
The error message told me! I think I sent the exact error message to you in teams a few days ago. Are you saying that your chat window is not an issue tracker? 😆 [4/17 3:26 PM] Ryan Nowak
/Users/ryan/.nuget/packages/nerdbank.gitversioning/3.1.71/build/Nerdbank.GitVersioning.targets(71,5): error MSB4018: The "Nerdbank.GitVersioning.Tasks.GetBuildVersion" task failed unexpectedly.
/Users/ryan/.nuget/packages/nerdbank.gitversioning/3.1.71/build/Nerdbank.GitVersioning.targets(71,5): error MSB4018: System.TypeInitializationException: The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception.
/Users/ryan/.nuget/packages/nerdbank.gitversioning/3.1.71/build/Nerdbank.GitVersioning.targets(71,5): error MSB4018: ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.DotNet.PlatformAbstractions, Version=2.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
/Users/ryan/.nuget/packages/nerdbank.gitversioning/3.1.71/build/Nerdbank.GitVersioning.targets(71,5): error MSB4018:
/Users/ryan/.nuget/packages/nerdbank.gitversioning/3.1.71/build/Nerdbank.GitVersioning.targets(71,5): error MSB4018: File name: 'Microsoft.DotNet.PlatformAbstractions, Version=2.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
/Users/ryan/.nuget/packages/nerdbank.gitversioning/3.1.71/build/Nerdbank.GitVersioning.targets(71,5): error MSB4018: at Nerdbank.GitVersioning.GitLoaderContext.GetNativeLibraryDirectory()
/Users/ryan/.nuget/packages/nerdbank.gitversioning/3.1.71/build/Nerdbank.GitVersioning.targets(71,5): error MSB4018: at Nerdbank.GitVersioning.GitLoaderContext.LoadUnmanagedDll(String unmanagedDllName)
/Users/ryan/.nuget/packages/nerdbank.gitversioning/3.1.71/build/Nerdbank.GitVersioning.targets(71,5): error MSB4018: at System.Runtime.Loader.AssemblyLoadContext.ResolveUnmanagedDll(String unmanagedDllName, IntPtr gchManagedAssemblyLoadContext)
/Users/ryan/.nuget/packages/nerdbank.gitversioning/3.1.71/build/Nerdbank.GitVersioning.targets(71,5): error MSB4018: at LibGit2Sharp.Core.NativeMethods.git_libgit2_init()
/Users/ryan/.nuget/packages/nerdbank.gitversioning/3.1.71/build/Nerdbank.GitVersioning.targets(71,5): error MSB4018: at LibGit2Sharp.Core.NativeMethods.InitializeNativeLibrary()
/Users/ryan/.nuget/packages/nerdbank.gitversioning/3.1.71/build/Nerdbank.GitVersioning.targets(71,5): error MSB4018: at LibGit2Sharp.Core.NativeMethods..cctor()
/Users/ryan/.nuget/packages/nerdbank.gitversioning/3.1.71/build/Nerdbank.GitVersioning.targets(71,5): error MSB4018:
/Users/ryan/.nuget/packages/nerdbank.gitversioning/3.1.71/build/Nerdbank.GitVersioning.targets(71,5): error MSB4018:
/Users/ryan/.nuget/packages/nerdbank.gitversioning/3.1.71/build/Nerdbank.GitVersioning.targets(71,5): error MSB4018: --- End of inner exception stack trace ---
/Users/ryan/.nuget/packages/nerdbank.gitversioning/3.1.71/build/Nerdbank.GitVersioning.targets(71,5): error MSB4018: at LibGit2Sharp.Core.NativeMethods.git_libgit2_opts(Int32 option, UInt32 level, String path)
/Users/ryan/.nuget/packages/nerdbank.gitversioning/3.1.71/build/Nerdbank.GitVersioning.targets(71,5): error MSB4018: at LibGit2Sharp.Core.Proxy.git_libgit2_opts_set_search_path(ConfigurationLevel level, String path)
/Users/ryan/.nuget/packages/nerdbank.gitversioning/3.1.71/build/Nerdbank.GitVersioning.targets(71,5): error MSB4018: at LibGit2Sharp.GlobalSettings.SetConfigSearchPaths(ConfigurationLevel level, String[] paths)
/Users/ryan/.nuget/packages/nerdbank.gitversioning/3.1.71/build/Nerdbank.GitVersioning.targets(71,5): error MSB4018: at Nerdbank.GitVersioning.GitExtensions.OpenGitRepo(String pathUnderGitRepo, Boolean useDefaultConfigSearchPaths)
/Users/ryan/.nuget/packages/nerdbank.gitversioning/3.1.71/build/Nerdbank.GitVersioning.targets(71,5): error MSB4018: at Nerdbank.GitVersioning.VersionOracle.Create(String projectDirectory, String gitRepoDirectory, ICloudBuild cloudBuild, Nullable`1 overrideBuildNumberOffset, String projectPathRelativeToGitRepoRoot)
/Users/ryan/.nuget/packages/nerdbank.gitversioning/3.1.71/build/Nerdbank.GitVersioning.targets(71,5): error MSB4018: at Nerdbank.GitVersioning.Tasks.GetBuildVersion.ExecuteInner() |
Just wanted to let you know that I have the same issue :)
Looking forward to having this built-in! |
As a workaround, I'm using global.json with: {
"sdk": {
"version": "3.1.100"
}
} |
For what it's worth, this is my workaround: var instance = Microsoft.Build.Locator.MSBuildLocator.RegisterDefaults();
AssemblyLoadContext.Default.Resolving += (assemblyLoadContext, assemblyName) =>
{
var path = Path.Combine(instance.MSBuildPath, assemblyName.Name + ".dll");
if (File.Exists(path))
{
return assemblyLoadContext.LoadFromAssemblyPath(path);
}
return null;
}; |
@rynowak @rainersigwald The Microsoft.DotNet.PlatformAbstractions.dll is supposed to ship with nerdbank.gitversioning.dll itself, but didn't because msbuild used to include it I guess and doesn't any more. Anyway, this was tracked by dotnet/Nerdbank.GitVersioning#466 and is fixed now. |
@zivkan i tried this workaround without success.. C:\Program Files\dotnet\sdk\3.1.401\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.FrameworkReferenceResolution.targets: (59, 5): errore imprevisto dell'attività "ProcessFrameworkReferences". In the "C:\Program Files\dotnet\sdk\3.1.401" folder i have NuGet.Frameworks.dll version 5.7.0.6 but it search for 5.7.0.7! |
…icts (#566) This change removes the dependency on NuGet.ProjectModel from the LanguageServer project and instead relies on the installed version of the binary. This change intends to avoid the dependency between the .Net Core SDK version and NuGet in MSBuildLocator. See issue #86 for additional reference. (microsoft/MSBuildLocator#86)
We encountered the same issue in a component of the Microsoft Quantum Development Kit. |
I got the same issue: Thanks Andy, your workaround also solved my issue. |
Adds an overload to permit supplying additional paths in which to search for MSBuild assemblies beyond the default. Uses this new overload to add the search path for NuGet assemblies for when in a VS install. The latter fixes #86.
Adds an overload to permit supplying additional paths in which to search for MSBuild assemblies beyond the default. Uses this new overload to add the search path for NuGet assemblies for when in a VS install. The latter fixes microsoft#86.
A heads up to anyone maybe struggling to get the workaround working.
That fails to compile, and gives me the following error:
But if you simply make sure the only thing you do in main is to register the resolver, and put everything else in a nother method. Then it will compile and the workaround works.
|
Using this with .NET sdk 3.1.X - I get errors like the following if I run any build targets.
I think that's happening here is that the tasks assembly
Microsoft.NET.Build.Tasks.dll
has references to NuGet's assemblies. If this were running as part of a dedicated msbuild process it would be fine because these would be in the load context. However since I'm hosting msbuild in my process they are not.I was able to work around this with my own assembly resolve handler, but it doesn't feel good to maintain a lot of assemblies that msbuild is usually responsible for providing.
The text was updated successfully, but these errors were encountered: