I have a requirement to create a NuGet package that contains an assembly and this assembly shall be copied in a subfolder of the consuming project *normally it would be copied in the base directory accordingly. So, if the output folder is like this bin\x64\Debug, then after the package is consumed and the solution is built, I should have the assembly placed inside bin\x64\Debug\someSubfolder. The inclusion of this package should not modify any other dll present in the output path!
Please note that the build platform and configuration defined above is just for example and it can be Debug/Release and AnyCPU/x64/x86.
Here are the few things which I have tried:
Approach 1:I have created a nuspec file and kept the file section like this:
<files><file src="some.props" target="build" /><file src="bin\AnyCPU\Debug\net8.0\some.framework.dll" target="lib\net8.0" /></files>
And I have the props file, which is a part of package, to make sure that the dll is correctly placed in the subfolder:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"><ItemGroup><!-- Find the some.framework.dll file in the NuGet package folder --><someAssembly Include="$(NuGetPackageRoot)\myPackage\$(PackageVersion)\lib\net8.0\some.framework.dll" /></ItemGroup><Target Name="CopyAssembly" AfterTargets="Build"><!-- Copy some.framework.dll version 4 to bin\net8.0\someSubfolder folder --><Copy SourceFiles="@(someAssembly)" DestinationFolder="$(OutputPath)\someSubfolder" /></Target></Project>
I'm able to generate and consume the package in the consuming project. However, with this approach, the some.framework.dll is correctly placed at bin\x64\Debug\someSubfolder but along with that, it is also overwriting an existing some.framework.dll with an older version present at bin\x64\Debug. This I have to avoid since I need both assemblies in both versions once in the base folder and once in the subfolder.The older version of the assembly is coming from a different package and needs to stay in the base folder. Our package shall deploy the assembly in the subFolder to not invalidate the original deployment.
Approach 2:I planned to place the dll as a contentFile inside the package. The packaging was successful, however, while consuming this package and during the build, I'm getting an error that the binaries are present in the contentFiles and the created package cannot be consumed without error.
Can someone help me with this request?
Thanks in advance!