在开始构建之前,NuGet恢复PostSharp软件包 [英] NuGet restoring PostSharp package before the build begins

查看:75
本文介绍了在开始构建之前,NuGet恢复PostSharp软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PostSharp,并且在我的项目文件中有以下目标描述:

I am using PostSharp and I have the following target description in my project file:

<Target Name="EnsurePostSharpImported" BeforeTargets="BeforeBuild" Condition="'$(PostSharp30Imported)' == ''">
  <Error Condition="!Exists('..\..\packages\PostSharp.3.1.33\tools\PostSharp.targets')" Text="This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them.  For more information, see http://www.postsharp.net/links/nuget-restore." />
  <Error Condition="Exists('..\..\packages\PostSharp.3.1.33\tools\PostSharp.targets')" Text="The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://www.postsharp.net/links/nuget-restore." />
</Target>

据我了解,当通过NuGet引用PostSharp时,这已添加到项目中,并且错误条件检查以下内容:

As far as I understand, this is added to the project when PostSharp is referenced through NuGet, and the error conditions check the following:

  • 第一个错误条件在PostSharp不可用时(即NuGet未能成功还原它)中断了构建.
  • 第二个错误情况会在NuShar在上一次构建中成功还原PostSharp时中断构建,但是该项目未包括在项目中,因此需要重新构建.
  • The first error condition breaks the build when PostSharp is not available (i.e. NuGet did not restore it successfully).
  • The second error condition breaks the build when PostSharp was successfully restored by NuGet on the last build but was therefore not included in the project, so therefore a rebuild is necessary.

但是,如果我在NuGet.Config.csproj file中具有以下配置,是否还需要第二个错误条件?

BUT, if I have the following configuration in NuGet.Config and .csproj file, is the second error condition even necessary?

NuGet.Config文件:

NuGet.Config file:

<configuration>
  <packageRestore>
    <!-- Allow NuGet to download missing packages -->
    <add key="enabled" value="True" />
    <!-- Automatically check for missing packages during build in Visual Studio -->
    <add key="automatic" value="True" />
  </packageRestore>
  ...
</configuration>

.csproj文件:

.csproj file:

<RestorePackages>true</RestorePackages>

据我了解,NuGet将在构建开始之前恢复丢失的软件包.第二种错误情况将根本无缘无故地破坏构建.

As far as I understand, NuGet will then restore the missing packages BEFORE the build even starts. The second error condition will essentially break the build for no reason at all.

注意:我正在使用Visual Studio 2013和NuGet 2.8.

Note: I am using Visual Studio 2013 and NuGet 2.8.

推荐答案

这取决于还原的完成方式以及安装的NuGet版本.错误消息似乎试图涵盖三种情况:

It depends on how the restore is done and which version of NuGet you have installed. It looks like the error messages are trying to cover three scenarios:

  1. 在未启用基于MSBuild的程序包还原的情况下进行构建(通过右键单击解决方案并选择启用程序包还原",可在Visual Studio中对其进行配置).
  2. 未启用基于MSBuild的程序包还原时在Visual Studio外部构建.
  3. 使用旧版本的NuGet使用Visual Studio进行构建,该版本不支持在构建之前进行自动还原.

如果您使用的是基于MSBuild的程序包还原,则还原将在构建过程中进行,并且此时将不会导入PostSharp文件,因此$(PostSharp30Imported)将为空,并显示第二条错误消息.至少我怀疑是这种情况.

If you are using the MSBuild based package restore then the restore will occur during the build and the PostSharp files will not be imported at this point so the $(PostSharp30Imported) will be empty and the second error message will be displayed. At least I suspect that is the case.

如果从命令行构建而不使用基于MSBuild的程序包还原,那么如果缺少NuGet程序包,则会看到第一条错误消息.

If you building from the command line and not using the MSBuild based package restore then you would see the first error message if the NuGet packages were missing.

如果您不使用基于MSBuild的程序包还原,而是在Visual Studio中使用最新版本的NuGet进行构建,那么您将正确地还原程序包,然后再进行任何构建.因此,PostSharp导入应该甚至在执行之前就可用于MSBuild.

If you are not using the MSBuild based package restore, and are building from within Visual Studio with a recent version of NuGet, then you are correct that the packages will be restored before anything is built at all. So the PostSharp imports should be available to MSBuild before it is even executed.

这篇关于在开始构建之前,NuGet恢复PostSharp软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆