Access denied to nukpg/nuspec files when running a Clean

Viewed 37

Recently in a large solution file I work on, I've started dual-targetting all my library projects as netstandard2.0;netstandard2.1, in order to take advantage of things like Span in applications which target net5.0, but still provide support for applications targetting net472. They've got AppendTargetFrameworkToBuildOutput set to true to ensure the different framework targets don't overwrite each other. Many of these projects also have GeneratePackageOnBuild set to true.

Since dual targetting, everyone that works on this project has had issues when running the Clean operation from their IDE. Generally at least one library (though not the same ones every time) will throw an error that says:

NuGet.Build.Tasks.Pack.targets(175, 5): [MSB3061] Unable to delete file "<library_path>\obj\Debug<project_name>.nuspec". Access to the path '<library_path>\obj\Debug<project_name>.nuspec' is denied.

I've also seen it happen with \bin\Debug\<project_name>.nupkg.

As best I can tell, this is happening because the Clean operation considers the netstandard2.0 and netstandard2.1 separate Clean operations, and they both happen to get scheduled at the same time (in the example I'm looking at, the netstandard2.0 build is scheduled on node 1, and the netstandard2.1 build is scheduled on node 3 at the same time). Then, they get to this file that both of them want to clean up, and either one blocks the other, or one beats the other to deleting it.

It seems like this should be a pretty common problem, but I haven't been successful at searching for a solution, which makes me think there's something obvious I must be missing. Any idea how to modify the csproj files to navigate this situation successfully?

0 Answers
Related