3

我正在使用NuGet 2.8.50506.491. 我创建了几个C#带有自定义 Microsoft Build 任务和帮助函数的项目。有一个目标文件。它看起来像这样。

<package >
  <metadata>
    <id>$id$</id>
    <version>$version$</version>
    <title>MyTasks</title>
    <authors>Werner Strydom</authors>
    <owners>Werner Strydom</owners>
    <licenseUrl>http://example.org/LICENSE</licenseUrl>
    <projectUrl>http://example.org/</projectUrl>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Sample tasks.</description>
    <releaseNotes>Initial Release</releaseNotes>
    <copyright>Copyright 2014 Werner Strydom</copyright>
  </metadata>
  <files>
    <file src="MyTasks.targets" target="build/net40" />
    <file src="bin\$configuration$\*.dll" target="build/net40" />
    <file src="bin\$configuration$\*.pdb" target="build/net40" />
  </files>
</package>

在 Visual Studio 项目文件中,我将BuildPackage属性设置为true

<PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{96535580-0000-0000-0000-2843D7EC2767}</ProjectGuid>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>MyTasks</RootNamespace>
    <AssemblyName>MyTasks</AssemblyName>
    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <BuildPackage Condition="'$(BuildPackage)' == ''">true</BuildPackage>
</PropertyGroup>

当我构建项目时,nupkg创建了一个。我将扩展名更改为zip并查看了文件的内容。项目的输出在lib/net40文件夹中。因此,当我将此包添加到另一个项目时,它还会添加对这些程序集的引用,这是不需要的,因为此包纯粹用于构建。

如何防止项目输出出现在 lib 文件夹中?

4

1 回答 1

3

BuildPackage 属性在 NuGet.targets 文件中定义。当 BuildPackage 为 true 时查看 NuGet.targets 文件,运行以下命令行:

NuGet.exe pack YourProject.csproj

如果您使用NuGet.exe pack YourProject.csproj,则项目的输出程序集始终添加到 lib 目录。查看 NuGet 源代码,您无法更改此行为,至少在不修改 NuGet 的情况下无法更改。

虽然使用NuGet pack YourProject.csproj将使用它找到的任何 YourProject.nuspec 文件来获取您无法在项目本身中定义的额外元数据,但您似乎无法阻止输出程序集被添加到 lib 目录。

另一种方法是在创建包时仅使用 .nuspec 文件。使用 .nuspec 文件,您可以完全控制进入 NuGet 包的内容。

NuGet.exe pack YourManifest.nuspec
于 2014-06-26T08:33:52.837 回答