交替使用msbuild和devenv构建相同的解决方案 [英] Building the same solution using msbuild and devenv interchangeably

查看:221
本文介绍了交替使用msbuild和devenv构建相同的解决方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这种情况经常发生,我首先使用msbuild在命令行上构建一些解决方案,运行了一段时间,但随后发现我需要更改和调试它.因此,我在Visual Studio中将其打开,并最终在Visual Studio中构建它.

It so happens quite often that I start by building some solution on the command line using msbuild, run it for awhile, but then discover that I need to change and debug it. So, I open it in Visual Studio and end up building it inside the Visual Studio.

发生的事情是,即使我什么都没做,VS都重建了解决方案的相当多的部分!

What happens is that VS rebuilts quite a few parts of the solution, even when I change nothing!

对其进行挖掘将显示以下内容:

Digging into it reveals the following:

在Visual Studio中进行内部构建会生成空的cs文件,并将其注入到Compile项目组中.当然,它们比已构建的二进制文件要新,因此devenv.exe会重建大量项目. .感谢/obj/debug breaking build中的TemporaryGeneratedFile_ [guid]

这真是个无赖.我通过重命名Microsoft.WorkflowBuildExtensions.targets文件来禁用此行为-我不执行工作流程.

This is a real bummer. I disabled this behavior by renaming the Microsoft.WorkflowBuildExtensions.targets file - I do not do workflow.

我想我可以破解CoreCompileDependsOn并以某种方式抵消Microsoft.WorkflowBuildExtensions.targets中的GenerateCompiledExpressionsTempFile目标,但这必须在190个项目中完成!这是一个严重的变化.

I suppose I could hack into CoreCompileDependsOn and somehow neutralize the GenerateCompiledExpressionsTempFile target from Microsoft.WorkflowBuildExtensions.targets, but this has to be done in 190 projects! This is a serious change.

devenv.exe似乎在乎总是将某些文件复制到输出目录,即使msbuild认为这不是问题.

devenv.exe seems to care about some files always being copied to the output directory, even if msbuild does not think it is a problem.

实际上,这是devenv.exe构建日志中的一行:

Indeed, here is a line from the devenv.exe build log:

Project 'HRCore.Tests' is not up to date. Project item 'C:\abc\UI\HRCore.Tests\HRImport\Import_missing_state_county.xml' has 'Copy to Output Directory' attribute set to 'Copy always'.

那又怎样? msbuild并不关心它,但是devenv关心.此文件不是HRCore.Tests的依赖项,msbuild正确.

So what? msbuild does not care about it, but devenv does. This files is not a dependency of the HRCore.Tests and msbuild got it right.

同时,我将其从Always更改为PreserveNewest.

In the meantime I changed it from Always to PreserveNewest.

无论如何,我很想知道如何消除这些差异.

Anyway, I am interested to know how can I eliminate these differences.

例如,即使使用msbuild进行构建,将BuildingInsideVisualStudio设置为true是一个好主意吗?

For example, is it a good idea to set BuildingInsideVisualStudio to true even when building with msbuild?

有什么想法吗?

P.S.

我们同时构建.NET和Silverlight.控制台应用程序,dll和Web应用程序.

We build both .NET and Silverlight. Console applications, dlls and web applications.

推荐答案

由于明确检查了$(BuildingInsideVisualStudio),该.targets文件的确在Visual Studio和命令行MsBuild之间引起了不同的行为:

That .targets file indeed causes different behavior between Visual Studio and command line MsBuild due to the explicit check for $(BuildingInsideVisualStudio):

  <PropertyGroup>
    <PrepareResourcesDependsOn>
      ValidationExtension;
      ExpressionBuildExtension;
      $(PrepareResourcesDependsOn)
    </PrepareResourcesDependsOn>
  </PropertyGroup>

  <PropertyGroup>
    <!-- Explicit check for Visual Studio here -->
    <CoreCompileDependsOn Condition="'$(BuildingInsideVisualStudio)' == 'true'">
        GenerateCompiledExpressionsTempFile;
        $(CoreCompileDependsOn)
    </CoreCompileDependsOn>   
  </PropertyGroup>

该显式检查使临时文件生成仅在我的配置中的Visual Studio中发生.制作这些文件是为了使您可以在Visual Studio中运行它们时进入其中并进行调试.

That explicit check makes the temp file generation only occur in Visual Studio in my configuration. These files are made so that you can step into them and debug them when running inside Visual Studio.

可以通过在项目文件中覆盖<GenerateCompiledExpressionsTempFilePathForEditing />为空来清除行为,以在命令行上明确清除其值.

The behavior can be turned off by overriding <GenerateCompiledExpressionsTempFilePathForEditing /> to empty in your project file of clearing it's value explicitly on the commandline.

/p:GenerateCompiledExpressionsTempFilePathForEditing=''

这是保护此行为的条件:

This is the condition that guards this behavior:

 <Target Name ="GenerateCompiledExpressionsTempFile" 
      Condition = "'$(GenerateCompiledExpressionsTempFilePathForEditing)' != ''">  

看看MsBuild路径,您应该能够通过在命令行上传递/p:DisableWorkflowCompiledExpression=true来完全关闭编译表达式的生成.

Looking at the MsBuild path, you should be able to turn off the generation of compiled expressions completely by passing /p:DisableWorkflowCompiledExpression=true on the commandline on.

您还可以覆盖CoreCompileDependsOn并从中删除GenerateCompiledExpressionsTempFile;项.

You can also override CoreCompileDependsOn and remove the GenerateCompiledExpressionsTempFile; item from it.

当在编辑器内部进行构建时,如果出现特殊行为",这确实是一个微不足道的事情.最后,我总是会错误地使Visual Studio表现为MsBuild,而不是相反.当BuildingInsideVisualStudio为true时,许多其他目标都将采用特殊服务或Host Compiler的可用性,让MsBuild认为它在Visual Studio中而实际上却不在Visual Studio中,这似乎是一个非常糟糕的主意.

It's really a pitty when there is "special behavior" when buildign inside the editor. In the end, I'd always err towards making Visual Studio behave as MsBuild and not the other way around. Many other targets will assume special services or the availability of the Host Compiler when BuildingInsideVisualStudio is true, it seems a very bad idea to make MsBuild think it's inside Visual Studio while it actually isn't.

这篇关于交替使用msbuild和devenv构建相同的解决方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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