nuget 是否仍然需要 Visual Studio 项目中的这些条目?

Does nuget still require these entries in Visual Studio projects?

我注意到没有这些 nuget 指令的新 .csproj 项目似乎工作正常。 这些是可以从项目中删除的过去遗留物吗? 我扫描了 nuget FAQ 但没有找到与此相关的任何内容。

我是 运行 Visual Studio 2013,也是 Xamarin Studio 的最新版本。

  <Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
  <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
    <PropertyGroup>
      <ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
    </PropertyGroup>
    <Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
  </Target>

如果您使用了启用 NuGet 包还原 菜单选项,则会添加这些特定目标。在这种情况下,可以删除这些目标。 Visual Studio 将自动恢复 NuGet 包,如果你安装了最新版本的 NuGet,没有这些额外的目标。此菜单选项已被 NuGet 团队弃用,我相信它会在某个时候被删除。

请注意,如果您在构建服务器上构建项目,您将需要创建一个额外的步骤来恢复 NuGet 包,使用 NuGet.exe 恢复,这将在解决方案构建时自动恢复在 MSBuild 的构建服务器上。

另请注意,如果您添加包含自己的 MSBuild .targets 文件的 NuGet 包,例如 Microsoft.Bcl.Build,NuGet 将添加非常相似的目标。在这种情况下,该项目将在没有 EnsureNuGetPackageBuildImports 目标的情况下工作,但需要导入 MSBuild .targets 文件的 Import 元素。将 EnsureNuGetPackageBuildImports 目标留在项目中确实会给您一条可能更有用的错误消息,说明如果未还原 NuGet 包,构建可能会失败的原因。