简体   繁体   English

使用 .nuspec 和 .targets (C++) 制作的 nuget package

[英]Consuming nuget package made with .nuspec and .targets (C++)

Struggling to get a compiled c++ dll (both x86 and x64) packaged up so that a C# library can consume it.努力将已编译的 c++ dll(x86 和 x64)打包,以便 ZD7EFA19FBE7D23D772FD 库可以使用它。

Managed to pack and push the dll using nuspec file however when using VS2019 package manager it successfully installs the package however the reference does not appear.管理使用 nuspec 文件打包和推送 dll 但是当使用 VS2019 package 管理器时,它成功安装了 package 但是没有出现参考。 (Any Cpu) (任何 CPU)

.nuspec .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>

As the consuming project is targeting .NET 4.0 I created a component1.targets file pointing to the same framework由于消费项目的目标是 .NET 4.0,我创建了一个指向同一框架的 component1.targets 文件

.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>

Your steps are in a mess.你的脚步一团糟。

You should note that the targets file should be named as <package_id>.targets`, the same name as the nuget package id or it could not work.您应该注意,目标文件应命名为 <package_id>.targets`,与 nuget package id 名称相同,否则无法正常工作。 See this link .请参阅此链接

Also , the targets file should be put into build folder of nupkg .此外,目标文件应放入nupkgbuild文件夹中。

That are the two importance tips.这是两个重要提示。

1) Please change your nuspec file to this: 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) Then , change your component1.targets to these: 2)然后,将您的component1.targets更改为:

You should remove the "" under "$(MSBuildThisFileDirectory)..\..\build\x64\component1.dll" .您应该删除"" "$(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) use nuget pack to repack the nuget package. 3)使用nuget pack重新包装 nuget package。 And before you install this new version of the nuget package, please clean nuget caches first or just delete all files under C:\Users\xxx(current user name)\.nuget\packages . And before you install this new version of the nuget package, please clean nuget caches first or just delete all files under C:\Users\xxx(current user name)\.nuget\packages .

And it works well in my side.它在我身边运作良好。

My nuget package is called testt , and I referenced ClassLibrary21.dll under x64 .我的 nuget package 被称为testt ,我在x64下引用了ClassLibrary21.dll

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM