【问题标题】:Create Nuget for net461 with content copy to output为 net461 创建 Nuget,并将内容复制到输出
【发布时间】:2019-12-23 13:56:25
【问题描述】:

我创建了一个针对 .NET Core 项目的 nuget 包。 这里的想法是添加 xxx.dll 作为引用,将本地复制为 false 并复制输出路径中子文件夹中的所有 DLL 以及子文​​件夹\resources 中的所有资源文件

针对 NET Core 3 的 nuspec 运行良好。

现在我想针对 NET Framework 4.6.1 做同样的事情。

但内容文件并未添加到项目中。 这是我的 nuspec 文件:

<?xml version="1.0"?>
<package  xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
  <metadata>    
    <id>xxx.Win.x64.ForIPS11</id>
    <version>15.5.3.4</version>
    <title>xxx toolkit</title>
    <authors>xxx Team</authors>
    <owners>xxx</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>xxx 15.5.3.4 x64 Windows to .NETFramework 4.6.1 for IPS 11</description>
    <releaseNotes></releaseNotes>
    <copyright>2020</copyright>
    <tags></tags>
    <dependencies>
      <group targetFramework=".NETFramework4.6.1" />
    </dependencies>
    <contentFiles>
        <files include="**\subfolder\resources\*.*"  buildAction="Content" copyToOutput="true" />
        <files include="**\subfolder\*.dll" buildAction="Content" copyToOutput="true" />
    </contentFiles>
  </metadata>
  <files>
    <file src="bin\xxx.dll" target="lib\net461" />
    <file src="resources\*.*" target="contentFiles\any\any\subfolder\resources"  />
    <file src="bin\*.dll" target="contentFiles\any\any\subfolder" />    
  </files>
</package>

我是否对 .NET Framework 目标使用了不兼容的标记? 知道如何完成这项工作吗?

编辑:我在目标项目中使用 VS2017 中的 packages.config 文件

【问题讨论】:

    标签: c# nuspec nuget-spec


    【解决方案1】:

    contentFiles 与 packages.config 方式不兼容

    这是另一种选择:

    Nuspec 文件:

    <?xml version="1.0"?>
    <package  xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
      <metadata>    
        <id>xxx.Win.x64.ForIPS11</id>
        <version>0.0.0</version>
        <title>xxx toolkit</title>
        <authors>xxx Team</authors>
        <owners>xxx</owners>
        <requireLicenseAcceptance>false</requireLicenseAcceptance>
        <description>xxx 0.0.0 x64 Windows to .NETFramework 4.6.1</description>
        <releaseNotes></releaseNotes>
        <copyright>2020</copyright>
        <dependencies>
           <group targetFramework=".NETFramework4.6.1" />
        </dependencies>
        <tags></tags>
      </metadata>
      <files>
        <file src="bin\xxx.dll" target="lib\net461" />
        <file src="resources\*.*" target="build\subfolder\resources"  />
        <file src="bin\*.dll" target="build\subfolder" />
        <file src="xxx.Win.x64.targets" target="build" />
        <file src="install.ps1" target="tools" />
      </files>
     </package>
    

    xxx.Win.x64.targets 复制子文件夹到输出

    <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <ItemGroup>
        <NativeLibs Include="$(MSBuildThisFileDirectory)**\*.*" />
        <None Include="@(NativeLibs)">
          <Link>%(RecursiveDir)%(FileName)%(Extension)</Link>
          <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </None>
      </ItemGroup>
    </Project>
    

    并 install.ps1 将本地复制标记为 false 到参考

    param($installPath, $toolsPath, $package, $project)
    $asms = $package.AssemblyReferences | %{$_.Name} 
    foreach ($reference in $project.Object.References) 
    {
        if ($asms -contains $reference.Name + ".dll") 
        {
            $reference.CopyLocal = $false;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-12-23
      • 2023-03-03
      • 2021-11-05
      • 2021-04-18
      • 2016-05-12
      • 2020-06-22
      • 1970-01-01
      相关资源
      最近更新 更多