在VS中,用于构建其他解决方案项目的MSBuild任务失败,但可与MSBuild.exe命令行一起使用 [英] MSBuild task to Build other solution projects fails in VS but works with MSBuild.exe command line

查看:218
本文介绍了在VS中,用于构建其他解决方案项目的MSBuild任务失败,但可与MSBuild.exe命令行一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义的MSBuild任务,除其他事项外,该任务还将嵌入式资源添加到解决方案中的其他项目中.添加资源后,我想构建这些项目,但是发现我无法在Visual Studio中正常工作.

I have a custom MSBuild task which among other things adds embedded resources to other projects in the solution. After adding the resources I'd like to then build those projects, but found I can't get this working within Visual Studio.

为了进行测试,我完全去除了自定义任务,并在Silverlight解决方案的Web项目中重新定义了一个简单的AfterBuild目标.目标使用MSBuild任务在解决方案中构建Silverlight应用程序项目,如下所示:

To test, I stripped out the custom task entirely and redefined a simple AfterBuild target in the web project of a Silverlight solution. The target uses the MSBuild task to build the Silverlight application project in the solution, and looks like this:

<Target Name="AfterBuild">
  <PropertyGroup>
    <LinkedProject>..\SilverlightApplication1\SilverlightApplication1.csproj</LinkedProject> 
  </PropertyGroup>

  <MSBuild Condition="'$(LinkedProject)' != '' "
    Projects="$(LinkedProject)"
    Targets="Build"
    Properties="CustomFlag=true" >
  </MSBuild>
</Target>

奇怪的是,当从命令行使用MSBuild时,它可以完美地工作,而在构建Web项目时,则不能在Visual Studio中工作.我以为这可能是Silverlight的某种问题,所以让该任务代替构建.NET类库项目,但是结果是相同的-它是从命令行运行的,而不是在VS中运行的.在VS中,没有实际错误-只是Csc任务不编译程序集并且不生成任何输出.

The odd thing is that this works perfectly when using MSBuild from the command line, yet does not work in Visual Studio when building the web project. I thought this might be some sort of Silverlight problem, and had the task build a .NET class library project instead, but the result was the same - it worked from the command line but not within VS. In VS there's no actual error - it's just that the Csc task does not compile the assembly and generates no output.

我需要做什么才能在Visual Studio中正常工作?

What do I need to do to get this working within Visual Studio?

推荐答案

将'UseHostCompilerIfAvailable = false'属性传递给MSBuild任务.

Pass the 'UseHostCompilerIfAvailable=false' property to the MSBuild task.

如果从MSBuild任务中调用csc,Visual Studio可能会严重中断,因为它会为其进程内宿主编译器重用初始项目构建设置.就我而言,我两次构建同一项目-默认构建是使用目标框架v3.5,而AfterBuild MSBuild任务指定了v4.0.我最终遇到了同样的问题-csc似乎可以运行,但是没有输出.我认为正在发生的事情是,在UseHostCompilerIfAvailable属性设置为true的情况下,csc调用了可重新使用我的初始项目设置的托管编译器,因此,即使命令行显示csc是构建"我的v4.0程序集,宿主编译器也只是覆盖我刚刚构建的v3.5!

It looks like Visual Studio breaks badly if csc is invoked from a MSBuild task as it reuses the initial project build settings for its in-process host compiler. In my case, I was building the same project twice - default build was using target framework v3.5, with a AfterBuild MSBuild task specifying v4.0. I ended up with the same issue - csc appeared to run but produced no output. I think what was happening was that with the UseHostCompilerIfAvailable property set to true, csc was calling the hosted compiler which reused my initial project settings, so even though the command line showed csc "building" my v4.0 assembly, the host compiler was simply overwriting the v3.5 one I had just built!

这篇关于在VS中,用于构建其他解决方案项目的MSBuild任务失败,但可与MSBuild.exe命令行一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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