NuGet 包目标 x86、x64 和 AnyCPU。

huangapple go评论63阅读模式
英文:

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

以下是翻译好的部分:

  1. 你的文件需要放在 build\{目标框架版本}\{架构} 中。

  2. 你需要添加一个 .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/文件夹中包含它一次(理论上可以!实际上不起作用)。

  3. 如果你想摆脱警告 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.

  1. Your files need to be placed in build\{target framework version}\{architecture}

  2. You'll need to add a .props file to include your lib's. This file should contain following content:

     &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
     &lt;Project ToolsVersion=&quot;4.0&quot; xmlns=&quot;http://schemas.microsoft.com/developer/msbuild/2003&quot;&gt;
       &lt;ItemGroup&gt;
           &lt;Reference Include=&quot;MyDll&quot;&gt;
               &lt;HintPath&gt;$(MSBuildThisFileDirectory)$(Platform)\MyDll.dll&lt;/HintPath&gt;
           &lt;/Reference&gt;
        &lt;/ItemGroup&gt;
     &lt;/Project&gt;
    

    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 name MyDll.props. Its final path should look something like this: build/net452/MyDll.props. You'll need to place it in every build/{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 the build/ folder (In theory, yes! In practice, it doesn't work).

  3. 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:
    -lib/net452/_._
    , You'll need to add an empty file with the name _._ in every lib\{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

&lt;package xmlns=&quot;http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd&quot;&gt;
    &lt;metadata minClientVersion=&quot;3.2&quot;&gt;
        ...
    &lt;/metadata&gt;
    &lt;files&gt;
		&lt;!-- .NETFramework 4.5.2 --&gt;
		&lt;file src=&quot;LSDOTNETCORE.props&quot; target=&quot;build\net452&quot; /&gt;
        &lt;file src=&quot;_._&quot; target=&quot;lib\net452&quot; /&gt;
	
        &lt;file src=&quot;Build\AnyCPU\Release\net452\LSDOTNETCORE.dll&quot; target=&quot;build\net452\AnyCPU&quot; /&gt;
        &lt;file src=&quot;Build\AnyCPU\Release\net452\LSDOTNETCORE.xml&quot; target=&quot;build\net452\AnyCPU&quot; /&gt;
        &lt;file src=&quot;Build\AnyCPU\Release\net452\LSDOTNETCORE.pdb&quot; target=&quot;build\net452\AnyCPU&quot; /&gt;	
		
        &lt;file src=&quot;Build\x86\Release\net452\LSDOTNETCORE.dll&quot; target=&quot;build\net452\x86&quot; /&gt;
        &lt;file src=&quot;Build\x86\Release\net452\LSDOTNETCORE.xml&quot; target=&quot;build\net452\x86&quot; /&gt;
        &lt;file src=&quot;Build\x86\Release\net452\LSDOTNETCORE.pdb&quot; target=&quot;build\net452\x86&quot; /&gt;
		
        &lt;file src=&quot;Build\x64\Release\net452\LSDOTNETCORE.dll&quot; target=&quot;build\net452\x64&quot; /&gt;
        &lt;file src=&quot;Build\x64\Release\net452\LSDOTNETCORE.xml&quot; target=&quot;build\net452\x64&quot; /&gt;
        &lt;file src=&quot;Build\x64\Release\net452\LSDOTNETCORE.pdb&quot; target=&quot;build\net452\x64&quot; /&gt;	
		
		&lt;!-- .NET-Standard --&gt;
		&lt;file src=&quot;LSDOTNETCORE.props&quot; target=&quot;build\netstandard2.1&quot; /&gt;
        &lt;file src=&quot;_._&quot; target=&quot;lib\netstandard2.1&quot; /&gt;
	
        &lt;file src=&quot;Build\AnyCPU\Release\netstandard2.1\LSDOTNETCORE.dll&quot; target=&quot;build\netstandard2.1\AnyCPU&quot; /&gt;
        &lt;file src=&quot;Build\AnyCPU\Release\netstandard2.1\LSDOTNETCORE.xml&quot; target=&quot;build\netstandard2.1\AnyCPU&quot; /&gt;
        &lt;file src=&quot;Build\AnyCPU\Release\netstandard2.1\LSDOTNETCORE.pdb&quot; target=&quot;build\netstandard2.1\AnyCPU&quot; /&gt;	
		
        &lt;file src=&quot;Build\x86\Release\netstandard2.1\LSDOTNETCORE.dll&quot; target=&quot;build\netstandard2.1\x86&quot; /&gt;
        &lt;file src=&quot;Build\x86\Release\netstandard2.1\LSDOTNETCORE.xml&quot; target=&quot;build\netstandard2.1\x86&quot; /&gt;
        &lt;file src=&quot;Build\x86\Release\netstandard2.1\LSDOTNETCORE.pdb&quot; target=&quot;build\netstandard2.1\x86&quot; /&gt;
		
        &lt;file src=&quot;Build\x64\Release\netstandard2.1\LSDOTNETCORE.dll&quot; target=&quot;build\netstandard2.1\x64&quot; /&gt;
        &lt;file src=&quot;Build\x64\Release\netstandard2.1\LSDOTNETCORE.xml&quot; target=&quot;build\netstandard2.1\x64&quot; /&gt;
        &lt;file src=&quot;Build\x64\Release\netstandard2.1\LSDOTNETCORE.pdb&quot; target=&quot;build\netstandard2.1\x64&quot; /&gt;		
    &lt;/files&gt;
&lt;/package&gt;

huangapple
  • 本文由 发表于 2023年4月14日 00:02:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/76007534.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定