8000 Unable to remove nuget directory with test project in solution · Issue #2 · gioce90/NuJet · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Unable to remove nuget directory with test project in solution #2

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

Open
Vectovox opened this issue Apr 30, 2025 · 3 comments
Open

Unable to remove nuget directory with test project in solution #2

Vectovox opened this issue Apr 30, 2025 · 3 comments
Assignees

Comments

@Vectovox
Copy link
Vectovox commented Apr 30, 2025

I'm having an issue with NuJet failing to remove the installed nuget package when making updates to a package project. MSBuild has locked access to the .dll file as it's used in a test project.

Unable to remove directory [...] Access to the path '[...].dll' is denied.

It kind of makes sense, as the test project references the package project. But as such, my current workflow is to:

  1. Restart Visual Studio (file lock is removed).
  2. Make package project changes and build it (as much as I want).
  3. Try the changes (e.g. by building the test project).
  4. Go to 1. for additional changes.

Is it expected in my situation or did I mess something up?

Solution

  • Test Project
    • ->Package Project
  • Package Project
    • -> NuJet
@gioce90 gioce90 self-assigned this May 7, 2025
@gioce90
Copy link
Owner
gioce90 commented May 7, 2025

Hi, I’m trying to reproduce this issue, but so far without success.

I created four projects:

  • Two projects that reference NuJet via PackageReference (i.e., NuJet "consumers"): one is an executable (Exe) project, the other a class library.
  • Two test projects, one for each consumer project (via ProjectReference of course)

None of them exhibit the problem you described.

You can find my attempt to reproduce the issue in this temporary repo: NuJet-Consumers-With-Test-Projects.

Could you take a look and let me know how your setup differs? I suspect there’s something else in your environment or setup that differs and might be causing the issue.

@Vectovox
Copy link
Author
Vectovox commented May 8, 2025

Thank you, and sorry for not updating the post! Since the above, I have worked more on my NuJet-consuming package, and I went from including a custom task to purely supplying build targets. I have not had the above issue since.

But I got the issue to resurface now by re-adding a simple task to the NuJet-consumer that runs on build for consumers of the package:

Setup

TetstTask.cs

    public class TestTask : Microsoft.Build.Utilities.Task
    {
        public override bool Execute()
        {
            Log.LogMessage(Microsoft.Build.Framework.MessageImportance.High, "MESSAGE!");
            return true;
        }
    }

build/package.props

<PropertyGroup>
	<_AppSettingsStronglyTyped_TaskFolder>$(MSBuildThisFileDirectory)..\tasks\netstandard2.0</_AppSettingsStronglyTyped_TaskFolder>
	<CustomTasksAssembly>$(_AppSettingsStronglyTyped_TaskFolder)\$(MSBuildThisFileName).dll</CustomTasksAssembly>
</PropertyGroup>

<UsingTask TaskName="$(MSBuildThisFileName).TestTask" AssemblyFile="$(CustomTasksAssembly)"/>

build/package.targets

<Target Name ="DE_InitBuild" BeforeTargets="Build">
	<TestTask />
</Target>

Package.csproj

<PropertyGroup>
	<GenerateDependencyFile>true</GenerateDependencyFile>
	<TargetsForTfmSpecificBuildOutput>
		$(TargetsForTfmSpecificBuildOutput);CopyProjectReferencesToPackage
	</TargetsForTfmSpecificBuildOutput>
	<BuildOutputTargetFolder>tasks</BuildOutputTargetFolder>
	<NoWarn>NU5100</NoWarn>
	<SuppressDependenciesWhenPacking>true</SuppressDependenciesWhenPacking>
</PropertyGroup>

<ItemGroup>
	<PackageReference Include="Microsoft.Build.Utilities.Core" Version="17.13.9" PrivateAssets="all" ExcludeAssets="Runtime" />
	<PackageReference Include="NuJet" Version="0.0.1">
		<PrivateAssets>all</PrivateAssets>
		<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
	</PackageReference>
</ItemGroup>

<ItemGroup>
	<Content Include="build\package.targets" PackagePath="build\" />
	<Content Include="build\package.props" PackagePath="build\" />
</ItemGroup>

<Target Name="CopyProjectReferencesToPackage" DependsOnTargets="ResolveReferences">
	<ItemGroup>
		<BuildOutputInPackage Include="@(ReferenceCopyLocalPaths)" TargetPath="%(ReferenceCopyLocalPaths.DestinationSubPath)" />
	</ItemGroup>
</Target>

<Target Name="AddBuildDependencyFileToBuiltProjectOutputGroupOutput" BeforeTargets="BuiltProjectOutputGroup" Condition=" '$(GenerateDependencyFile)' == 'true'">
	<ItemGroup>
		<BuiltProjectOutputGroupOutput Include="$(ProjectDepsFilePath)" TargetPath="$(ProjectDepsFileName)" FinalOutputPath="$(ProjectDepsFilePath)" />
	</ItemGroup>
</Target>

Note: Source based on this

Effect

In short, any project adding a reference to my package now gets "MESSAGE" printed on its build. Once that happens, I can not rebuild the package as above.

I assume something under the hood of Visual Studio keeps the custom task assembly loaded?

Also: Just want to take the opportunity to thank you for NuJet. It's been very useful!

@gioce90
Copy link
Owner
gioce90 commented May 14, 2025

Hi @Vectovox , I'm glad you like NuJet. Any feedback, appreciation, issue or anything else is very welcome to improve the project. Thank you.

Anyway, I will investigate your situation calmly, for now I haven't been able to reproduce the error on my machine. I'm trying to imitate the contents you shared, but evidently I'm missing something to make everything work.

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
0