c# - 使用 .nuspec 和 .targets (C++) 制作的 nuget 包
问题描述
努力将已编译的 c++ dll(x86 和 x64)打包,以便 C# 库可以使用它。
管理使用 nuspec 文件打包和推送 dll,但是当使用 VS2019 包管理器时,它成功安装了包,但是没有出现引用。(任何 CPU)
.nuspec
<?xml version="1.0"?>
<package >
<metadata>
<id>component1</id>
<version>1.0.0</version>
<description>mycomponent</description>
<authors>Me</authors>
</metadata>
<files>
<file src="32\component1.dll" target="build\x86" />
<file src="64\component1.dll" target="build\x64" />
<file src="component1.targets" target="lib\net40" />
</files>
</package>
由于消费项目的目标是 .NET 4.0,我创建了一个指向同一框架的 component1.targets 文件
.targets
<ItemGroup Condition=" '$(Platform)' == 'x64' ">
<Reference Include="component1">
<HintPath>"$(MSBuildThisFileDirectory)..\..\build\x64\component1.dll"</HintPath>
</Reference>
</ItemGroup>
<ItemGroup Condition=" '$(Platform)' == 'x86' OR '$(Platform)' == 'AnyCPU' OR '$(Platform)' == 'Any CPU' ">
<Reference Include="component1">
<HintPath>$(MSBuildThisFileDirectory)..\..\build\x32\component1.dll</HintPath>
</Reference>
</ItemGroup>
解决方案
你的脚步一团糟。
您应该注意,目标文件应命名为 <package_id>.targets`,与 nuget 包 ID 同名,否则将无法工作。请参阅此链接。
此外,目标文件应放入nupkgbuild
文件夹中。
这是两个重要提示。
1)请将您的nuspec
文件更改为:
<?xml version="1.0"?>
<package >
<metadata>
<id>component1</id>
<version>1.0.0</version>
<description>mycomponent</description>
<authors>Me</authors>
</metadata>
<files>
<file src="32\component1.dll" target="build\x86" />
<file src="64\component1.dll" target="build\x64" />
<file src="component1.targets" target="build" />
</files>
</package>
2)然后,将您的更改component1.targets
为:
您应该删除""
下面的"$(MSBuildThisFileDirectory)..\..\build\x64\component1.dll"
.
<Project>
<ItemGroup Condition=" '$(Platform)' == 'x64' ">
<Reference Include="component1">
<HintPath>$(MSBuildThisFileDirectory)..\build\x64\component1.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup Condition=" '$(Platform)' == 'x86' OR '$(Platform)' == 'AnyCPU' OR '$(Platform)' == 'Any CPU' ">
<Reference Include="component1">
<HintPath>$(MSBuildThisFileDirectory)..\build\x32\component1.dll</HintPath>
</Reference>
</ItemGroup>
</Project>
3) 使用nuget pack
重新打包nuget包。在安装这个新版本的 nuget 包之前,请先清理 nuget 缓存或删除C:\Users\xxx(current user name)\.nuget\packages
.
它在我身边运作良好。
我的 nuget 包被称为testt
,我ClassLibrary21.dll
在x64
.
推荐阅读
- reactjs - 更新反应 useState 挂钩嵌套二维数组
- amazon-web-services - 当我更改路径时,基于 AWS ALB 目标组路径的路由不起作用
- java - 在eclipse中构建我的java应用程序后出错
- reactjs - http://localhost:5000/auth/google/callback 404 错误
- jmeter - 我可以使用 csvdataconfig 中的变量作为 jmeter 目录列表中的源目录吗
- python - 更新谷歌表上的特定标签 - Python
- ckeditor - 如何从外部书签链接跳转到 React Ckeditor 5 段落?
- python - 从 groupby 中的前一个组中获取值
- windows - 在汇编代码中使用 printf 函数
- android - Recyclerview 在滚动上重新创建动态芯片