使用nuget打包.Net和Native DLL
Posted 力为
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用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>
以上是关于使用nuget打包.Net和Native DLL的主要内容,如果未能解决你的问题,请参考以下文章
C#封装.net framework函数库,并打包发布dll函数库到nuget服务器