How to copy a dll present in my Nuget package to a subfolder in the consuming project directory?

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 binx64Debug, then after the package is consumed and the solution is built, I should have the assembly placed inside binx64DebugsomeSubfolder. 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:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><files>
<file src="some.props" target="build" />
<file src="binAnyCPUDebugnet8.0some.framework.dll" target="libnet8.0" />
</files>
</code>
<code><files> <file src="some.props" target="build" /> <file src="binAnyCPUDebugnet8.0some.framework.dll" target="libnet8.0" /> </files> </code>
<files>
    <file src="some.props" target="build" />
    <file src="binAnyCPUDebugnet8.0some.framework.dll" target="libnet8.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:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><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)libnet8.0some.framework.dll" />
</ItemGroup>
<Target Name="CopyAssembly" AfterTargets="Build">
<!-- Copy some.framework.dll version 4 to binnet8.0someSubfolder folder -->
<Copy SourceFiles="@(someAssembly)" DestinationFolder="$(OutputPath)someSubfolder" />
</Target>
</Project>
</code>
<code><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)libnet8.0some.framework.dll" /> </ItemGroup> <Target Name="CopyAssembly" AfterTargets="Build"> <!-- Copy some.framework.dll version 4 to binnet8.0someSubfolder folder --> <Copy SourceFiles="@(someAssembly)" DestinationFolder="$(OutputPath)someSubfolder" /> </Target> </Project> </code>
<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)libnet8.0some.framework.dll" />
  </ItemGroup>

  <Target Name="CopyAssembly" AfterTargets="Build">
    <!-- Copy some.framework.dll version 4 to binnet8.0someSubfolder 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 binx64DebugsomeSubfolder but along with that, it is also overwriting an existing some.framework.dll with an older version present at binx64Debug. 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!

New contributor

Abhinav Mathur is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật