使用nuget打包.Net和Native DLL

目標

使用Nuget管理x86/x64多平臺的,適應AnyCPU, x86,x64編譯選項

 

步驟

1. 設置Package.nuspec

<?xml version="1.0"?>
<package >
  <metadata>
    <id>XYZ</id>
    <version>1.0.6</version>
    <authors>liwei</authors>
    <owners>liwei</owners>
    <licenseUrl>http://www.my.com</licenseUrl>
    <projectUrl>http://www.my.com</projectUrl>
    <iconUrl>http://www.my.com/icon.ico</iconUrl>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>HelloWorld</description>
    <releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
    <copyright>Copyright 2020</copyright>
    <tags>XYZ XYZ</tags>
  </metadata>
  <files>
      <file src="lib\**" target="lib" />
      <file src="runtimes\win-x64\native\**" target="runtimes\win-x64\native\" />
      <file src="runtimes\win-x86\native\**" target="runtimes\win-x86\native\" />
      <file src="XYZ.props" target="build\net"/>
  </files>
</package>

2. 設置XYZ.props用於copy Native DLL

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

    <ItemGroup Condition="'$(Platform)' == 'AnyCPU' ">
        <Content Include="$(MSBuildThisFileDirectory)..\..\runtimes\win-x64\native\**">
            <CopyToOutputDirectory>Always</CopyToOutputDirectory>
            <Link>x64\%(Filename)%(Extension)</Link>
        </Content>
        <Content Include="$(MSBuildThisFileDirectory)..\..\runtimes\win-x86\native\**">
            <CopyToOutputDirectory>Always</CopyToOutputDirectory>
            <Link>x86\%(Filename)%(Extension)</Link>
        </Content>
    </ItemGroup>
    
    <ItemGroup Condition=" '$(Platform)' == 'x64' ">
        <Content Include="$(MSBuildThisFileDirectory)..\..\runtimes\win-x64\native\**">
            <CopyToOutputDirectory>Always</CopyToOutputDirectory>
            <Link>x64\%(Filename)%(Extension)</Link>
        </Content>
    </ItemGroup>

    <ItemGroup Condition=" '$(Platform)' == 'x86'">
        <Content Include="$(MSBuildThisFileDirectory)..\..\runtimes\win-x86\native\**">
            <CopyToOutputDirectory>Always</CopyToOutputDirectory>
            <Link>x86\%(Filename)%(Extension)</Link>
        </Content>
    </ItemGroup>

</Project>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章