我正在使用 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 时添加到项目中的,错误情况检查如下:
- The 第一个错误条件当 PostSharp 不可用时(即 NuGet 未成功恢复),会破坏构建。
- The 第二个错误条件当 NuGet 在上次构建中成功恢复 PostSharp 但因此未包含在项目中时,会破坏构建,因此需要重新构建。
BUT,如果我有以下配置NuGet.Config
and .csproj file
,第二个错误条件是否必要?
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
file:
<RestorePackages>true</RestorePackages>
据我了解,NuGet 将在构建开始之前恢复丢失的包。第二个错误条件基本上会无缘无故地破坏构建。
注意:我使用的是 Visual Studio 2013 和 NuGet 2.8。
这取决于恢复的完成方式以及您安装的 NuGet 版本。看起来错误消息试图涵盖三种情况:
- 在不启用基于 MSBuild 的包还原的情况下进行构建(通过右键单击解决方案并选择“启用包还原”在 Visual Studio 中进行配置)。
- 当未启用基于 MSBuild 的包还原时,在 Visual Studio 外部进行构建。
- 使用旧版本的 NuGet 通过 Visual Studio 进行构建,该旧版本不支持构建前的自动还原。
如果您使用基于 MSBuild 的包还原,则还原将在构建期间发生,此时不会导入 PostSharp 文件,因此 $(PostSharp30Imported) 将为空,并且将显示第二条错误消息。至少我怀疑情况确实如此。
如果从命令行构建并且不使用基于 MSBuild 的包还原,那么如果 NuGet 包丢失,您将看到第一条错误消息。
如果您没有使用基于 MSBuild 的包还原,而是使用最新版本的 NuGet 从 Visual Studio 中进行构建,那么您认为包将在构建任何内容之前进行还原是正确的。因此,PostSharp 导入在执行之前就应该可供 MSBuild 使用。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)