【发布时间】:2014-08-15 17:18:01
【问题描述】:
我有许多项目的解决方案,其中一些使用 PostSharp。我最近从使用 NuGet MSBuild 集成还原切换到 NuGet 自动还原。这会导致在构建开始之前为所有包恢复所有必需的包。这很好用,除了现在我经常遇到 PostSharp 会因错误而导致构建失败的问题:
构建恢复了 NuGet 包。再次构建项目以在构建中包含这些包。如需更多信息,请参阅http://www.postsharp.net/links/nuget-restore。
当我编辑项目文件时,我看到以下条目:
<Import Project="..\..\packages\PostSharp.3.1.46\tools\PostSharp.targets" Condition="Exists('..\..\packages\PostSharp.3.1.46\tools\PostSharp.targets')" />
<Target Name="EnsurePostSharpImported" BeforeTargets="BeforeBuild" Condition="'$(PostSharp30Imported)' == ''">
<Error Condition="!Exists('..\..\packages\PostSharp.3.1.46\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.46\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 包存在于我的机器上但也不存在于我的机器上时,会出现错误情况。似乎这些条件已被评估,因为变量 $(PostSharp30Imported) 从未设置。我假设这取决于恢复的 MSBuild 集成版本,但我没有足够的 MSBuild 经验来确定。
我可以通过简单地删除项目文件中的第二个错误条件来解决该问题(因为我保证在项目构建时拥有这些文件),但似乎任何升级或添加 PostSharp 原因项目文件恢复到旧方式并阻止我的解决方案构建。
这是 PostSharp 中的错误,还是在使用不会导致此问题的 NuGet 自动恢复时我应该使用 PostSharp 的其他方式?
【问题讨论】:
标签: c# visual-studio nuget postsharp