NuGet pack 命令未将文件复制到输出

NuGet pack 命令未将文件复制到输出

我目前正在将公司的共享类库项目从项目引用移至 NuGet 包引用。我已成功转换除一个项目之外的所有项目,这是一个针对 .NET v4.7.2 的较旧的 VB.NET 项目。在构建或打包过程中我没有遇到任何错误,并且包已成功创建,但有一系列外部 DLL 和我需要复制到 NuGet 包中的 PDB 文件。

这是 .nuspec 文件:

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
  <metadata>
    <id>Project.Core</id>
    <version>$version$</version>
    <title>$title$</title>
    <authors>Author Here</authors>
    <owners>Owner Here</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>$description$</description>
    <releaseNotes>Initial release.</releaseNotes>
    <copyright>Copyright © 2019</copyright>
  </metadata>

  <files>
    <file src="bin\$configuration$\Project.Core.pdb" target="lib\net472" />
    <file src="bin\$configuration$\FirstExternal.dll" target="lib\net472" />
    <file src="bin\$configuration$\SecondExternal.dll" target="lib\net472" />
    <file src="bin\$configuration$\ThirdExternal.dll" target="lib\net472" />
    <file src="bin\$configuration$\FourthExternal.dll" target="lib\net472" />
    <file src="bin\$configuration$\FifthExternal.dll" target="lib\net472" />
    <file src="bin\$configuration$\SixthExternal.dll" target="lib\net472" />
  </files>
</package>

项目文件如下:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}</ProjectGuid>
    <OutputType>Library</OutputType>
    <RootNamespace>
    </RootNamespace>
    <AssemblyName>Project.Core</AssemblyName>
    <Description>Core Class Library.</Description>
    <MyType>Windows</MyType>
    <SignAssembly>true</SignAssembly>
    <AssemblyOriginatorKeyFile>AssemblyKey.snk</AssemblyOriginatorKeyFile>
    <DelaySign>false</DelaySign>
    <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
    <MapFileExtensions>true</MapFileExtensions>
    <UseApplicationTrust>false</UseApplicationTrust>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <DefineDebug>true</DefineDebug>
    <DefineTrace>true</DefineTrace>
    <OutputPath>bin\Debug\</OutputPath>
    <DocumentationFile>Project.Core.xml</DocumentationFile>
    <NoWarn>41999,42016,42017,42018,42019,42020,42021,42022,42032,42036,42353,42354,42355</NoWarn>
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
    <CodeAnalysisRuleSet>..\StyleCop-Recommended.ruleset</CodeAnalysisRuleSet>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DebugType>none</DebugType>
    <DefineTrace>true</DefineTrace>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DocumentationFile>Project.Core.xml</DocumentationFile>
    <NoWarn>41999,42016,42017,42018,42019,42020,42021,42022,42032,42036,42353,42354,42355</NoWarn>
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
    <CodeAnalysisRuleSet>..\..\StyleCop-Recommended.ruleset</CodeAnalysisRuleSet>
  </PropertyGroup>

{Some more configuration definitions.}

  <PropertyGroup>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
  </PropertyGroup>
  <ItemGroup>

    {Bunch of NuGet references.}

    <Reference Include="FirstExternal">
      <HintPath>..\Lib\FirstExternal\FirstExternal.dll</HintPath>
    </Reference>
    <Reference Include="SecondExternal, Version=1.2.2389.14294, Culture=neutral, PublicKeyToken=60064b713d9de8f4, processorArchitecture=MSIL">
      <HintPath>..\Lib\SecondExternal\1.2\SecondExternal.dll</HintPath>
      <SpecificVersion>False</SpecificVersion>
      <Private>True</Private>
    </Reference>
    <Reference Include="ThirdExternal, Version=11.1.0.0, Culture=neutral, PublicKeyToken=6d02be8724ca751c, processorArchitecture=MSIL">
      <SpecificVersion>False</SpecificVersion>
      <HintPath>..\Lib\ThirdExternal\6.5\ThirdExternal.dll</HintPath>
    </Reference>
    <Reference Include="FourthExternal, Version=6.4.0.0, Culture=neutral, PublicKeyToken=6d02be8724ca751c, processorArchitecture=MSIL">
      <SpecificVersion>False</SpecificVersion>
      <HintPath>..\Lib\FourthExternal\6.5\FourthExternal.dll</HintPath>
    </Reference>
    <Reference Include="FifthExternal, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821, processorArchitecture=MSIL">
      <SpecificVersion>False</SpecificVersion>
      <HintPath>..\Lib\FifthExternal\2.0.5\FifthExternal.dll</HintPath>
    </Reference>
    <Reference Include="SixthExternal">
      <HintPath>..\Lib\SixthExternal\0.3.5_projectCustom\SixthExternal.dll</HintPath>
    </Reference>


    <Reference Include="System" />
    <Reference Include="System.ComponentModel.DataAnnotations" />
    <Reference Include="System.configuration" />
    <Reference Include="System.Core">
      <RequiredTargetFramework>3.5</RequiredTargetFramework>
    </Reference>
    <Reference Include="System.Data" />
    <Reference Include="System.Drawing" />
    <Reference Include="System.EnterpriseServices" />
    <Reference Include="System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
    <Reference Include="System.Runtime.Serialization">
      <RequiredTargetFramework>3.0</RequiredTargetFramework>
    </Reference>
    <Reference Include="System.ServiceModel">
      <RequiredTargetFramework>3.0</RequiredTargetFramework>
    </Reference>
    <Reference Include="System.Transactions" />
    <Reference Include="System.Web" />
    <Reference Include="System.Web.ApplicationServices" />
    <Reference Include="System.Web.Extensions" />
    <Reference Include="System.Web.Services" />
    <Reference Include="System.Windows.Forms" />
    <Reference Include="System.Xml" />
    <Reference Include="System.Xml.Linq" />
  </ItemGroup>
  <ItemGroup>
    <Import Include="Microsoft.VisualBasic" />
    <Import Include="System" />
    <Import Include="System.Collections" />
    <Import Include="System.Collections.Generic" />
    <Import Include="System.Data" />
    <Import Include="System.Diagnostics" />
    <Import Include="System.Linq" />
    <Import Include="System.Windows.Forms.ComponentModel.Com2Interop" />
  </ItemGroup>
  <ItemGroup Label="CodeFiles">
    {Lots and lots of compile elements.}
  </ItemGroup>
  <ItemGroup>
    <EmbeddedResource Include="My Project\Resources.resx">
      <Generator>VbMyResourcesResXFileCodeGenerator</Generator>
      <CustomToolNamespace>My.Resources</CustomToolNamespace>
      <SubType>Designer</SubType>
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <LastGenOutput>Resources.Designer.vb</LastGenOutput>
    </EmbeddedResource>
    <EmbeddedResource Include="Resources\Messages.resx">
      <SubType>Designer</SubType>
    </EmbeddedResource>
  </ItemGroup>
  <ItemGroup>
    <None Include="packages.config" />
    <None Include="My Project\Application.myapp">
      <Generator>MyApplicationCodeGenerator</Generator>
      <LastGenOutput>Application.Designer.vb</LastGenOutput>
    </None>
    <None Include="My Project\Settings.settings">
      <Generator>SettingsSingleFileGenerator</Generator>
      <CustomToolNamespace>My</CustomToolNamespace>
      <LastGenOutput>Settings.Designer.vb</LastGenOutput>
    </None>
  </ItemGroup>
  <ItemGroup>
    <WebReferences Include="Web References\" />
  </ItemGroup>
  <ItemGroup>
    <WCFMetadata Include="Service References\" />
  </ItemGroup>
  <ItemGroup>
    <Folder Include="Folder\SubFolder\" />
  </ItemGroup>
  <Import Project="$(MSBuildBinPath)\Microsoft.VisualBasic.targets" />
</Project>

我运行以下命令:nuget pack .\Path\To\Project\Project.vbproj -Properties Configuration=Debug -OutputDirectory E:\Local\Nuget-Repo -Verbosity detailed但只有项目的 DLL 和文档 XML 文件被放入 nupkg 的 lib\net472 文件夹中。

请记住,这个项目比我在公司任职的时间早了好久。因此,项目文件中可能有一些我不熟悉的非常古老的元素。

NuGet Version: 5.0.2.5988
Microsoft (R) Build Engine version 16.1.76+g14b0a930a7 for .NET Framework

如果需要任何额外信息,请告诉我。

答案1

我建立了一个全新的 VB.NET 项目,并使用基本相同的 .nuspec 文件测试了 pack 命令,并且运行良好。

经过进一步调查,我发现项目文件名必须与 .nuspec 文件名完全匹配。我重命名了 .nuspec 文件以匹配我的项目文件的名称,现在可以正常工作了。

相关内容