简体   繁体   English

如何在 Visual Studio 的生成后事件中访问生成警告?

[英]How to access build warnings in a post-build event in Visual Studio?

General task .一般任务 My task is to make a build (of a set of C# projects) failed if there exists such DLLs which were not found and thus were not copied to the output folder.我的任务是,如果存在未找到且因此未复制到输出文件夹的此类 DLL,则使(一组C#项目的)构建失败。 It seems that a corresponding warning is not a warning of a compiler, thus I cannot provide a warning code to the "Treat warnings as errors" option in Visual Studio.似乎相应的警告不是编译器的警告,因此我无法为 Visual Studio 中的“将警告视为错误”选项提供警告代码。 The workaround I found is to use MsBuild like it is described here .我发现的解决方法是使用MsBuild,就像这里描述的那样。 However I still cannot find any solution for building with a Visual Studio .但是我仍然找不到任何使用Visual Studio构建的解决方案。

Question .问题 Is there a way to obtain a build log and especially build warnings in a post-build event in Visual Studio and make the build failed if some exact warnings exist?有没有办法在Visual Studio的构建后事件中获取构建日志,尤其是构建警告,并在存在某些确切警告时使构建失败?

What I looked at .我看着什么 Looked here , but suggested macro is not a convinient solution.这里,但建议的宏不是一个方便的解决方案。 According to this and this Visual Studio does not save build logs for C# projects.根据这个这个Visual Studio不保存C#项目的构建日志。

More specific .更具体 I have been asked to provide information about the specific warning which I want to make an error of.我被要求提供有关我想要出错的特定警告的信息。 This is "MSB3245: Could not resolve this reference. Could not locate the assembly..."这是“MSB3245:无法解析此引用。无法找到程序集...”

You could check files in AfterBuild target.您可以检查 AfterBuild 目标中的文件。 For example:例如:

<Target Name="AfterBuild">
    <Error Condition="Exists('$(MSBuildProjectDirectory)\bin\Debug\ClassLibrary1.pdb')==false" Text="file not exist"/>
  </Target>

I have been asked to post a conclusion from the discussion of the current question and my company's experience.我被要求根据当前问题的讨论和我公司的经验发表结论。 So here it is.所以在这里。

Answer .回答 There is no way "to access build warnings in a post-build event in Visual Studio " for managed code projects (excluding some very specific cases, see suggestion about TFS ).对于托管代码项目,无法“在Visual Studio中的生成后事件中访问生成警告”(不包括一些非常具体的情况,请参阅有关TFS 的建议)。

Workaround .解决方法 Currently we use MsBuild to catch warnings and transform them into errors as it is described here .目前我们使用的MSBuild赶上警告,因为它是描述它们转化为错误在这里 So developers do not have access to this functionality while they use standard Visual Studio (or ReSharper ) build process.因此,开发人员在使用标准Visual Studio (或ReSharper )构建过程时无法访问此功能。 However our continuous integration server uses exactly MsBuild and thus it informs us about warnings and errors which we are interested in.然而,我们的持续集成服务器完全使用MsBuild ,因此它会通知我们我们感兴趣的警告和错误。

Other considerations .其他考虑

  1. If the "Treat warnings as errors" functionality in MsBuild were introduced, one could utilize it for similar purposes.如果MsBuild中引入了“将警告视为错误”功能,则可以将其用于类似目的。
  2. One could create a special MsBuild task analyzing the references in project files (.csproj) and comparing this refernces with the files copied to the output folder.可以创建一个特殊的MsBuild任务,分析项目文件 (.csproj) 中的引用并将此引用与复制到输出文件夹的文件进行比较。 This task must be injected in every necessary project file.此任务必须注入到每个必要的项目文件中。
  3. Some components of TFS probably save build logs (not familiar with this). TFS 的某些组件可能会保存构建日志(对此不熟悉)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM