英文:
NuGet targeting x86, x64 and AnyCPU in one Package
问题
由于我在以下问题上花费了太多时间,我想与您分享我的结果:
NuGet允许定位许多不同的设置,但涉及到一些高级内容时,它的文档不够完善。还有很多不同的东西散乱四处,但这一切都很混乱。
因此,我遇到了这个问题:如何在单个软件包中包含不同目标版本的x86、x64和Any CPU构建?
英文:
Since I was spending way to much on time on the following question, I wanted to share my results with you:
NuGet allows to target quite a lot of different setups, but when it comes to some advanced stuff, It's documentation isn't great. There is also quite a lot of different stuff floating around but it's all a big mess.
So I was stuck with this: How do I include a x86, x64 and Any CPU build with different target versions in just a single package?
答案1
得分: 1
以下是翻译好的部分:
-
你的文件需要放在
build\{目标框架版本}\{架构}
中。 -
你需要添加一个
.props
文件以包含你的库。该文件应包含以下内容:<?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <ItemGroup> <Reference Include="MyDll"> <HintPath>$(MSBuildThisFileDirectory)$(Platform)\MyDll.dll</HintPath> </Reference> </ItemGroup> </Project>
确保将
MyDll
替换为你的包和.dll名称!*它必须保存在每个
build/{目标框架版本}
文件夹中,并且必须使用名称MyDll.props
。其最终路径应该看起来像这样:build/net452/MyDll.props
。你需要将它放在每个build/{目标框架版本}
目录中。这需要这样做,以便NuGet停止让人讨厌,以便包含我们的.props
文件。遗憾的是,无法仅在build/
文件夹中包含它一次(理论上可以!实际上不起作用)。 -
如果你想摆脱警告
WARNUNG: NU5127: This package does not contain a lib/ or ref/ folder, and will therefore be treated as compatible for all frameworks. Since framework specific files were found under the build/ directory for net452, consider creating the following empty files to correctly narrow the compatibility of the package: -lib/net452/_._
,你需要在每个lib\{目标框架版本}
目录中添加一个名为_._
的空文件。
最终结构:
你组装的NuGet包应该如下所示:
{根目录}/
build/
net452/
MyDll.props
AnyCPU/
MyDll.dll
MyDll.xml
MyDll.pdb
x86/
MyDll.dll
MyDll.xml
MyDll.pdb
x64/
MyDll.dll
MyDll.xml
MyDll.pdb
netstandard2.1/
MyDll.props
AnyCPU/
...
.../
lib/
net452/
_._
netstandard2.1/
_._
示例 .nuspec
:
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata minClientVersion="3.2">
...
</metadata>
<files>
<!-- .NETFramework 4.5.2 -->
<file src="LSDOTNETCORE.props" target="build\net452" />
<file src="_._" target="lib\net452" />
<file src="Build\AnyCPU\Release\net452\LSDOTNETCORE.dll" target="build\net452\AnyCPU" />
<file src="Build\AnyCPU\Release\net452\LSDOTNETCORE.xml" target="build\net452\AnyCPU" />
<file src="Build\AnyCPU\Release\net452\LSDOTNETCORE.pdb" target="build\net452\AnyCPU" />
<file src="Build\x86\Release\net452\LSDOTNETCORE.dll" target="build\net452\x86" />
<file src="Build\x86\Release\net452\LSDOTNETCORE.xml" target="build\net452\x86" />
<file src="Build\x86\Release\net452\LSDOTNETCORE.pdb" target="build\net452\x86" />
<file src="Build\x64\Release\net452\LSDOTNETCORE.dll" target="build\net452\x64" />
<file src="Build\x64\Release\net452\LSDOTNETCORE.xml" target="build\net452\x64" />
<file src="Build\x64\Release\net452\LSDOTNETCORE.pdb" target="build\net452\x64" />
<!-- .NET-Standard -->
<file src="LSDOTNETCORE.props" target="build\netstandard2.1" />
<file src="_._" target="lib\netstandard2.1" />
<file src="Build\AnyCPU\Release\netstandard2.1\LSDOTNETCORE.dll" target="build\netstandard2.1\AnyCPU" />
<file src="Build\AnyCPU\Release\netstandard2.1\LSDOTNETCORE.xml" target="build\netstandard2.1\AnyCPU" />
<file src="Build\AnyCPU\Release\netstandard2.1\LSDOTNETCORE.pdb" target="build\netstandard2.1\AnyCPU" />
<file src="Build\x86\Release\netstandard2.1\LSDOTNETCORE.dll" target="build\netstandard2.1\x86" />
<file src="Build\x86\Release\netstandard2.1\LSDOTNETCORE.xml" target="build\netstandard2.1\x86" />
<file src="Build\x86\Release\netstandard2.1\LSDOTNETCORE.pdb" target="build\netstandard2.1\x86" />
<file src="Build\x64\Release\netstandard2.1\LSDOTNETCORE.dll" target="build\netstandard2.1\x64" />
<file src="Build\x64\Release\netstandard2.1\LSDOTNETCORE.xml" target="build\netstandard2.1\x64" />
<file src="Build\x64\Release\netstandard2.1\LSDOTNETCORE.pdb" target="build\netstandard2.1\x64" />
</files>
</package>
英文:
There are two existing SO-answers regarding this. Both of them lack a few details.
It's actually quite simple. At least, if you've spend around 5 hours on this.
-
Your files need to be placed in
build\{target framework version}\{architecture}
-
You'll need to add a
.props
file to include your lib's. This file should contain following content:<?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <ItemGroup> <Reference Include="MyDll"> <HintPath>$(MSBuildThisFileDirectory)$(Platform)\MyDll.dll</HintPath> </Reference> </ItemGroup> </Project>
make sure to replace the
MyDll
with your package and .dll name!*It has to be saved in every
build/{target framework version}
folder and has to use the nameMyDll.props
. Its final path should look something like this:build/net452/MyDll.props
. You'll need to place it in everybuild/{target framework version}
directory. This needs to be done so that NuGet stops being annoying and to get it to include our.props
file. Sadly, it's not possible to include it only once in thebuild/
folder (In theory, yes! In practice, it doesn't work). -
If you want to get rid of the warning
WARNUNG: NU5127: This package does not contain a lib/ or ref/ folder, and will therefore be treated as compatible for all frameworks. Since framework specific files were found under the build/ directory for net452, consider creating the following empty files to correctly narrow the compatibility of the package:
, You'll need to add an empty file with the name
-lib/net452/_.__._
in everylib\{target framework version}
directory.
Final structure:
Your assembled NuGet package should look like this:
{root}/
build/
net452/
MyDll.props
AnyCPU/
MyDll.dll
MyDll.xml
MyDll.pdb
x86/
MyDll.dll
MyDll.xml
MyDll.pdb
x64/
MyDll.dll
MyDll.xml
MyDll.pdb
netstandard2.1/
MyDll.props
AnyCPU/
...
.../
lib/
net452/
_._
netstandard2.1/
_._
Example .nuspec
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata minClientVersion="3.2">
...
</metadata>
<files>
<!-- .NETFramework 4.5.2 -->
<file src="LSDOTNETCORE.props" target="build\net452" />
<file src="_._" target="lib\net452" />
<file src="Build\AnyCPU\Release\net452\LSDOTNETCORE.dll" target="build\net452\AnyCPU" />
<file src="Build\AnyCPU\Release\net452\LSDOTNETCORE.xml" target="build\net452\AnyCPU" />
<file src="Build\AnyCPU\Release\net452\LSDOTNETCORE.pdb" target="build\net452\AnyCPU" />
<file src="Build\x86\Release\net452\LSDOTNETCORE.dll" target="build\net452\x86" />
<file src="Build\x86\Release\net452\LSDOTNETCORE.xml" target="build\net452\x86" />
<file src="Build\x86\Release\net452\LSDOTNETCORE.pdb" target="build\net452\x86" />
<file src="Build\x64\Release\net452\LSDOTNETCORE.dll" target="build\net452\x64" />
<file src="Build\x64\Release\net452\LSDOTNETCORE.xml" target="build\net452\x64" />
<file src="Build\x64\Release\net452\LSDOTNETCORE.pdb" target="build\net452\x64" />
<!-- .NET-Standard -->
<file src="LSDOTNETCORE.props" target="build\netstandard2.1" />
<file src="_._" target="lib\netstandard2.1" />
<file src="Build\AnyCPU\Release\netstandard2.1\LSDOTNETCORE.dll" target="build\netstandard2.1\AnyCPU" />
<file src="Build\AnyCPU\Release\netstandard2.1\LSDOTNETCORE.xml" target="build\netstandard2.1\AnyCPU" />
<file src="Build\AnyCPU\Release\netstandard2.1\LSDOTNETCORE.pdb" target="build\netstandard2.1\AnyCPU" />
<file src="Build\x86\Release\netstandard2.1\LSDOTNETCORE.dll" target="build\netstandard2.1\x86" />
<file src="Build\x86\Release\netstandard2.1\LSDOTNETCORE.xml" target="build\netstandard2.1\x86" />
<file src="Build\x86\Release\netstandard2.1\LSDOTNETCORE.pdb" target="build\netstandard2.1\x86" />
<file src="Build\x64\Release\netstandard2.1\LSDOTNETCORE.dll" target="build\netstandard2.1\x64" />
<file src="Build\x64\Release\netstandard2.1\LSDOTNETCORE.xml" target="build\netstandard2.1\x64" />
<file src="Build\x64\Release\netstandard2.1\LSDOTNETCORE.pdb" target="build\netstandard2.1\x64" />
</files>
</package>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论