Unexpected csproj itemgroup/NativeLibs Remove entry on file rename

552 Views Asked by At

I am getting an unexpected ItemGroup entry for each rename.

If I start with interface public interface IDoStuff and rename it to IDoStuffRename I get this in my csproj on save:

<ItemGroup>
   <NativeLibs Remove="IDoStuffRename.cs" />
</ItemGroup>

It does not happen on delete or move. This heavily pollutes the csproj file over time after continuous refactoring.

Any idea why this is happening and how I can avoid that extra entry?

I currently undo it manually.

3

There are 3 best solutions below

0
Spikee On BEST ANSWER

Confirmed, it's indeed nuget package ABCPdf that's causing this behavior. I can repeatably reproduce it by adding the package (or not). I get it on a dotnet core solution with version 11x and 12x.

Manually removing these references for now.

PS: If someone can elaborate what NativeLibs Remove means for the build I would appreciate it.

2
OnceUponATimeInTheWest On

It is difficult to see how the ABCpdf NuGet package could cause this issue because ultimately the NuGet package is just a set of files in a zip.

It is Visual Studio that puts these files in different places depending on what it sees in the NuGet package. But even that only happens at the point of installation.

When it comes to refactoring the only culprit here can be Visual Studio because it is the only one that can change the project file and indeed there is no installation occurring.

So in short - this is a bug or perhaps a feature of Visual Studio which you will see with a variety of NuGet packages when performing similar tasks.

The solution will be to upgrade Visual Studio and hope that Microsoft resolve the issue.

4
MemeDeveloper On

At a quick guess I'd say yes this is AbcPdf doing this, as seems the WebSupergoo guys use this (in their ABCpdf.targets file)

<ItemGroup>
   <NativeLibs Include="$(MSBuildThisFileDirectory)**\*.*" Exclude="$(MSBuildThisFileDirectory)**\*.targets;$(MSBuildThisFileDirectory)**\*Settings.exe;$(MSBuildThisFileDirectory)**\TaskGardener.exe"/>
   <None Include="@(NativeLibs)" Visible="False">
     <Link>%(RecursiveDir)%(FileName)%(Extension)</Link>
     <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
   </None>
 </ItemGroup>

i.e. what is TaskGardener.exe and Settings.exe doing?

Don't have time to bottom this out... but pretty sure this is a 2x coincidence!