Укажите архитектуру и режимы отладки / выпуска в файле * nuspec для публикации проекта DLL C ++

У меня есть проект Visual Studio C ++, который создает DLL для архитектур x86 и x64 в режимах отладки и выпуска. Я должен опубликовать этот пакет как пакет nuget с учетом этих спецификаций. Так что в моем пакете должно быть 4 библиотеки DLL. У меня вопрос, как указать x86, x64 в моем файле nuspec. Я думал, следует ли его указывать в поле target каждого файла, но я не могу найти никакой документации о том, как точно указать эти спецификации. Мой файл nuspec выглядит следующим образом:

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
    <metadata>
        <!-- Required elements-->
        <id>counterpartylookup</id>
        
        <version>0.0.0</version>
        
        <description>counterpartylookup/v140/win32/x86/x64</description>
        
        <authors>***</authors>

        <!-- Optional elements -->
        <!-- ... -->
        <owners>...</owners>
        
        <licenseUrl>***</licenseUrl>
        
        <projectUrl>***</projectUrl>
        
        <dependencies>
            ***
        </dependencies>
        
        <tags> {vc140, win32, x64, x86, dynamic, C++, native}</tags>
    </metadata>

        <files>
            <file src="..\shared\v140\bin\x64\Release\CounterPartyLookup.dll" target="lib" />
            <file src="..\shared\v140\bin\x64\Debug\CounterPartyLookup.dll" target="lib" />
             <file src="..\shared\v140\bin\x86\Release\CounterPartyLookup.dll" target="lib" />
             <file src="..\shared\v140\bin\x86\Debug\CounterPartyLookup.dll" target="lib" />
        </files>
    <!-- Optional 'files' node -->
</package>

person Mahshid Khezri    schedule 16.09.2020    source источник
comment
Вы хотели сослаться на этот пакет c ++ nuget на основе конкретной платформы в сетевом проекте?   -  person Mr Qian    schedule 21.09.2020


Ответы (2)


У меня вопрос, как указать x86, x64 в моем файле nuspec.

Вам необходимо поместить библиотеки DLL в папку с именем runtimes в подпапках с именем {platform} - {architecture} \ lib {framework} или {platform} - {architecture} \ native.

Структура папок:

  \runtimes
    \x86
        \Debug
              \Release
    \x64
        \Debug
              \Release

Файл nuspec выглядит так:

<files>
    <file src="..\shared\v140\bin\x64\Release\CounterPartyLookup.dll" target="runtimes\ x64\Release " />
    <file src="..\shared\v140\bin\x64\Debug\CounterPartyLookup.dll" target=" runtimes\ x64\Debug " />
     <file src="..\shared\v140\bin\x86\Release\CounterPartyLookup.dll" target=" runtimes\ x86\Release " />
     <file src="..\shared\v140\bin\x86\Debug\CounterPartyLookup.dll" target=" runtimes\ x86\Debug " />
</files>

Связанные документы: Папки для конкретной архитектуры и Добавление собственных библиотек реализации.

person LoLance    schedule 18.09.2020

Или вы можете попробовать другой:

1) создайте файл с именем <package_id>.targets file в папке проекта. На вашей стороне, вы должны назвать это как counterpartylookup.targets:

напишите под ним:

<Project>
    <ItemGroup Condition="'$(Platform)'=='x64' and '$(Cofiguration)'=='Debug'">
        <Reference Include="$(MSBuildThisFileDirectory)..\Reference\x64\Debug\CounterPartyLookup.dll"></Reference>
    </ItemGroup>
    <ItemGroup Condition="'$(Platform)'=='x86' and '$(Cofiguration)'=='Debug'">
        <Reference Include="$(MSBuildThisFileDirectory)..\Reference\x86\Debug\CounterPartyLookup.dll"></Reference>
    </ItemGroup>
    <ItemGroup Condition="'$(Platform)'=='x64' and '$(Cofiguration)'=='Release'">
        <Reference Include="$(MSBuildThisFileDirectory)..\Reference\x64\Release\CounterPartyLookup.dll"></Reference>
    </ItemGroup>
    <ItemGroup Condition="'$(Platform)'=='x86' and '$(Cofiguration)'=='Release'">
        <Reference Include="$(MSBuildThisFileDirectory)..\Reference\x86\Release\CounterPartyLookup.dll"></Reference>
    </ItemGroup>
</Project>

2) измените файл NUSPEC:

<files>
    <file src="..\shared\v140\bin\x64\Release\CounterPartyLookup.dll" target="Reference\x64\Release" />
    <file src="..\shared\v140\bin\x64\Debug\CounterPartyLookup.dll" target="Reference\x64\Debug" />
     <file src="..\shared\v140\bin\x86\Release\CounterPartyLookup.dll" target="Reference\x86\Release" />
     <file src="..\shared\v140\bin\x86\Debug\CounterPartyLookup.dll" target="Reference\x86\Debug" />
     <file src="counterpartylookup.targets" target="build"/>
</files>

3) перепакуйте свой проект C ++, а затем перед установкой нового удалите все кеши nuget в C:\Users\xxx(current user)\.nuget\packages

person Mr Qian    schedule 21.09.2020