Repository navigation
Description
MSBuild.ProjectCreation: 8.0.0
Hello. I came across this library at the MSBuildSdks and started using it in an experimental project. Everything was working great until recently when my tests began to fail to build my generated projects when executing tests for the .NET 5 and .NET 6 target platforms (the test project targets those platforms). As far as I can tell, the issue comes up as soon as I install the more recent .NET 6 6.0.300 SDK on the machine. Seeing it on Windows, Linux, and MacOS. I currently target .NET Core 3.1, .NET 5, and .NET 6 in my test projects. The tests behave as expected for .NET Core 3.1, but fail with the following for .NET 5 and .NET 6 with the following output:
Target "ResolvePackageAssets" in file "C:\Program Files\dotnet\sdk\6.0.300\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets" from project "C:\Users\craig\AppData\Local\Temp\CentralBuildOutputTests\ct0vn00m.bwj\src\MyClassLibrary\MyClassLibrary.csproj" (target "ResolveLockFileReferences" depends on it):
Using "ResolvePackageAssets" task from assembly "C:\Program Files\dotnet\sdk\6.0.300\Sdks\Microsoft.NET.Sdk\targets\..\tools\net6.0\Microsoft.NET.Build.Tasks.dll".
Task "ResolvePackageAssets"
Unable to use package assets cache due to I/O error. This can occur when the same project is built more than once in parallel. Performance may be degraded, but the build result will not be impacted.
The "ResolvePackageAssets" task failed unexpectedly.
System.IO.FileLoadException: Could not load file or assembly 'NuGet.Frameworks, Version=6.2.0.146, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Could not find or load a specific file. (0x80131621)
File name: 'NuGet.Frameworks, Version=6.2.0.146, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
---> System.IO.FileLoadException: Could not load file or assembly 'NuGet.Frameworks, Version=6.2.0.146, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
at System.Runtime.Loader.AssemblyLoadContext.LoadFromPath(IntPtr ptrNativeAssemblyLoadContext, String ilPath, String niPath, ObjectHandleOnStack retAssembly)
at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)
at Microsoft.Build.Shared.MSBuildLoadContext.Load(AssemblyName assemblyName)
at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingLoad(AssemblyName assemblyName)
at System.Runtime.Loader.AssemblyLoadContext.Resolve(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)
at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter.CanResolveApphostFromFrameworkReference()
at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter.WriteApphostsForShimRuntimeIdentifiers()
at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter.WriteItemGroup(Action writeItems)
at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter.WriteItemGroups()
at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter.Write()
at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter.WriteToMemoryStream()
at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheReader.CreateReaderFromMemory(ResolvePackageAssets task, Byte[] settingsHash)
at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheReader..ctor(ResolvePackageAssets task)
at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ReadItemGroups()
at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ExecuteCore()
at Microsoft.NET.Build.Tasks.TaskBase.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask)
Done executing task "ResolvePackageAssets" -- FAILED.
Done building target "ResolvePackageAssets" in project "MyClassLibrary.csproj" -- FAILED.
I don't think my tests are doing anything overly complicated, but I've been wrong before. I haven't been able to workaround it on my dev machine. Even forcing it to use the 6.0.2xx version using the global.json didn't work. But, I was able to specifically install the 6.0.2xx SDKs on the build agents as a workaround for now and that did work, so i'm fairly certain it is the newer SDK.
Have you seen anything similar on your end? Any suggestions?
Activity
Lock build to .NET 6 SDK 6.0.203 and remove .NET 5 from test platforms (
Apply transitive update for NuGet.Frameworks
craigktreasure commentedon Jun 17, 2022
A workaround appears to be to apply a transitive update for NuGet.Frameworks to update to the latest version.
Update dependencies and fix MSBuild.ProjectCreation issues (#33)
jeffkl commentedon Jun 20, 2022
Yes you've discovered the problem with NuGet.Frameworks being referenced by
Microsoft.NET.Test.Sdk:This causes your unit test to need that particular version in the output directory and causes collisions. Specifically, the error includes Could not find or load a specific file. This is because MSBuild is loading NuGet assemblies that ship with .NET SDK/Visual Studio which can be different than the version than are in the package dependency graph of your app. I try to keep
MSBuild.ProjectCreationupdated to match the latest version that is out there but have fallen behind. Do you want to send a PR to update the version used byMSBuild.ProjectCreation?craigktreasure commentedon Jun 21, 2022
Well, for the record, it looks like you already have a more recent update (6.2.0) to that dependency checked in, but haven't shipped an updated release. 8.0.0 currently depends on 6.1.0. The latest is 6.2.1. I'm happy to submit a PR to update to 6.2.1. We'd just need an updated release following that update.
craigktreasure commentedon Jun 21, 2022
To be honest, i'm surprised Dependabot isn't helping out here.
jeffkl commentedon Jun 21, 2022
I was getting bombarded with emails from dependabot every single day so I changed the frequency to monthly 😄 My curse for having so many repos. I can try changing it to weekly so you don't have to send a PR.
4755c0d
craigktreasure commentedon Jun 21, 2022
Haha, i completely understand. I think i can manage the one character PR 😉.
craigktreasure commentedon Jun 21, 2022
Looks like Dependabot beat me to it.
jeffkl commentedon Jun 21, 2022
Fixed by #175 and available in https://github.com/jeffkl/MSBuildProjectCreator/releases/tag/v8.2.1