为net461创建Nuget,将内容复制到输出

时间:2019-12-23 13:56:25

标签: c# nuspec nuget-spec

我已经创建了一个针对.NET Core项目的nuget包。 这里的想法是添加xxx.dll作为引用,并将本地副本复制为false 并将所有DLL复制到输出路径的子文件夹中,并将所有资源文件复制到subfolder \ 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文件

1 个答案:

答案 0 :(得分:0)

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标记将本地副本复制为引用

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