复制C DLL以构建任何C#项目的输出,以扩展为参考
Copy C++ dlls to build output of any C# project that reference them by extension
我有一个C#
库,该库引用了一些C++CLI
项目,其中包含一些 C++
库编译为dlls
。
因此,总的来说,在使用我的库的任何应用程序的运行时,我当然需要C#
和CLI
dlls
,但也需要所有C++
,即使CLI
Project引用了它们,默认情况下也不会复制它们。
使用预构建事件手动复制它们。
,但我不仅需要每个应用程序项目添加它们,而且我也想将我的库以NuGet
发布,并且无法控制引用项目的属性。
有解决方法吗?特定于NuGet
软件包的事件。
我喜欢Hans Passants评论。他的答案减少了复制数据的数量,并允许无缝使用AnyCPU。
- 我的解决方案是WPF项目使用的东西。支持旧项目文件的项目类型,Nuget不太支持.NET CORE或.NET标准项目。但是.NET标准中没有C CLI。我们只有X64组件,我的消费者只有内部,因此不需要关心Win32。新的Nuget语法可以为这些DLL提供很大的控制,但实际上我对我的学习曲线和Nuget都没有完成。
所以这就是我对严格包装DLL的使用。人们可以调试我的DLL,我将调试DLL,PDB放入包装中,它们仅在我们公司内部消耗。如果用户将配置更改为调试,我确实编写了这些汇编的包装文件的目标文件。
本机Dll< - C CLI包装器< - C#便利载荷
'nuspec
<?xml version="1.0"?>
<package xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<description></description>
<id>yourId</id>
<version>$version$</version>
<authors></authors>
<!-- Only done because at the beginning I copied the native dll into the lib/net461 folder which gets automatically referenced -->
<references>
<reference file="yourCSharpProject.dll" />
<reference file="yourInteropProject.dll" /> <!-- if needed -->
</references>
</metadata>
<files>
<!-- the target file will copy my native dlls into the target file -->
<file src="target**" target="build"/>
<!-- copy all debug and release of ... Native.dlls, pdbs, xml -->
<!-- usage hint ** preserves the folder structure, debug and release -->
<file src="binx64**YourNative.*" target="libnative" />
<!-- copy all debug and release of ... Interop.lls, pdbs, xml -->
<file src="binx64Release.*" target="libnet461" />
</files>
</package>
'target yourpackagename.target
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="CopyBinaries" BeforeTargets="BeforeBuild">
<CreateItem Include="$(MSBuildThisFileDirectory)../lib/native/$(Configuration)/*" >
<Output TaskParameter="Include" ItemName="SomeImportantName" />
</CreateItem>
<Copy SourceFiles="@(SomeImportantName)"
DestinationFolder="$(Outputpath)"
SkipUnchangedFiles="true" />
</Target>
</Project>
相关文章:
- 递归函数计算序列中的平方和(并输出过程)
- 如何使用 < 和 > 命令获取 c++ 中的输入和输出?
- 请解释"函数1(p1,p2,p3);"的输出
- C++:将控制台输出存储在宏中更好吗
- 创建一个函数以在输入为负数或零时输出字符串.第一次执行用户定义的函数
- 如何在OMNET++中指定与命令行参数组合的输出文件名
- 是否可以通过C++扩展强制多个python进程共享同一内存
- 为什么我的代码在输出中增加了93天
- static_assert在宏中,但也可以扩展到可以用作函数参数的东西
- 如何从void函数输出字符串
- 输入到文件并输出到另一个文件,并将流文件传递给函数
- AES加密到解密未正确输出
- 如何将c++程序的一些输出传递给shell,以便在shell中使用
- 使用C++程序合并排序没有得到正确的输出
- 复制C DLL以构建任何C#项目的输出,以扩展为参考
- 基于python版本的C++python扩展的输出差异
- 在 Buck 中,如何扩展 genrule 输出目录
- 我想获得输出2^64,而C 中没有任何扩展
- 流式输出扩展 ASCII
- 扩展内联汇编:输入和输出相同的变量