NuGet pack 指令不會將檔案複製到輸出

NuGet pack 指令不會將檔案複製到輸出

我目前正在將公司的共享類庫項目從項目引用移動到 NuGet 包引用。我已成功轉換除一個項目之外的所有項目,該項目是一個針對 .NET v4.7.2 的較舊的 VB.NET 項目。我在建置或打包過程中沒有遇到任何錯誤,並且套件已成功創建,但是我需要將一系列外部 DLL 和 PDB 檔案複製到 NuGet 套件中。

這是 .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 檔案以匹配我的專案文件的名稱,現在它可以工作了。

相關內容