【发布时间】:2014-06-26 19:09:04
【问题描述】:
我正在使用 PostSharp,我的项目文件中有以下目标描述:
<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时添加到项目中的,错误情况检查如下:
- 当 PostSharp 不可用时,第一个错误条件会中断构建(即 NuGet 未成功恢复它)。
- 第二个错误条件在最后一次构建中由 NuGet 成功恢复 PostSharp 但因此未包含在项目中时会中断构建,因此需要重新构建。
但是,如果我在NuGet.Config 和.csproj file 中有以下配置,那么第二个错误条件是否必要?
NuGet.Config文件:
<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文件:
<RestorePackages>true</RestorePackages>
据我了解,NuGet 将在构建开始之前恢复丢失的包。第二个错误条件基本上会无缘无故地破坏构建。
注意:我使用的是 Visual Studio 2013 和 NuGet 2.8。
【问题讨论】:
标签: visual-studio msbuild nuget nuget-package postsharp