Visual Studio 2008中的自定义锁MSBuild任务组件 [英] Visual Studio 2008 locks custom MSBuild Task assemblies

查看:121
本文介绍了Visual Studio 2008中的自定义锁MSBuild任务组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发构建一个 ORM层一个自定义的MSBuild任务,并在项目中使用它。我被保持到MSBuild任务DLL和不放手Visual Studio的行为阻碍。

I'm developing a custom MSBuild task that builds an ORM layer, and using it in a project. I'm being hampered by Visual Studio's behaviour of holding onto MSBuild task DLLs and not letting go.

我想整理我的解决方案是这样;

I'd like to organize my solution like this;

My Solution
 |
 +- (1) ORM Layer Custom Task Project
 |  |
 |  +- BuildOrmLayerTask.cs     // here's my task
 |  
 +- (2) Business Logic Project  // and here's the project that uses it.
    |
    +- <UsingTask TaskName="BuildOrmLayerTask" AssemblyFile="$(TaskAssembly)" />



然而,当工程(2)建立,它锁定到从项目的组件(1)。所以现在我不能(1)再次而不关闭该解决方案,并重新打开它建项目。

However, when project (2) builds, it locks onto the assembly from project (1). So now I can't build project (1) again without closing the solution and re-opening it.

有没有什么方法可以让我整理东西,使自定义生成任务没有保持由Visual Studio锁定?

Is there any way I can organize things so that the custom build task is not kept locked by Visual Studio?

推荐答案

编辑: 赛义德·易卜拉欣·哈希米,谁从字面上写上的MSBuild书,暗示的 AppDomainIsolatedTask 以一个更好的方法类)

( Sayed Ibrahim Hashimi, who literally wrote the book on msbuild, suggests the AppDomainIsolatedTask class for a better approach)

我已经成功地解决了这个一个自己...

I've managed to solve this one myself...

此发现的从丹·莫斯利论坛上发帖,从微软的MSBuild开发商之一:

Found this forum post from Dan Moseley, one of the MSBuild developers from Microsoft:

您好,

不幸的是,这是因为在
主要AppDomain中加载的MSBuild任务组件。在CLR不允许组件从一个AppDomain卸载
,因为这可以让他们的
部分重要的优化。

Unfortunately this is because MSBuild loads task assemblies in the primary appdomain. The CLR does not allow assemblies to unload from an appdomain as this allows important optimizations on their part.

唯一的解决办法,我建议是召唤出tomsbuild.exe至
构建使用任务的项目。要做到这一点,创建
MSBuild.exe<>作为VS外部工具

The only workarounds I suggest is to call out tomsbuild.exe to build the projects that use the task. To do this, create MSBuild.exe <> as an external tool in VS.

丹结果
开发商的MSBuild

DanMoseley - MSFT

Dan
developer on msbuild
DanMoseley - MSFT

所以,似乎停止锁,必须酿出了一个新的MSBuild.exe处理。它不可能是在Visual Studio中运行,因为当的MSBuild运行的,它加载任务到Visual Studio的主要应用领域,而且永远不能被卸载。

So, it seems that to stop the locks, you must spawn out a new MSBuild.exe process. It can't be the one that runs inside Visual Studio, because when MSBuild runs, it loads the tasks into Visual Studio's primary app domain, and that can never be unloaded.


  • 创建一个新的MSBuild项目(一.csproj的或类似的),这将覆盖建设的目标,并执行您的自定义操作,如;

  • create a new MSBuild project (a .csproj or similar) which overrides the 'Build' Target and performs your custom actions, eg;

<!-- fragment of Prebuild.csproj -->   
<Target Name="Build">   
     <BuildOrmLayerTask Repository="$(Repository)" />   
</Target>


  • 将它添加到Visual Studio,如果你想要的,但使用Configuration Manager,以确保它是*不*内置的任何配置。就让VS照顾源控制和类似的东西,而不是建设。

  • Add it to visual studio if you want, but use Configuration Manager to make sure it is *not*built in any configuration. Just let VS take care of source control and suchlike, not building.

    编辑依赖于项目的.csproj文件预生成.csproj的。添加使用 Exec的任务,调用的MSBuild一个 BeforeBuild 目标。这将启动一个新的过程,并且当这一过程结束时,该文件的锁被释放。示例;

    Edit the .csproj file of the project that depends on Prebuild.csproj. Add a BeforeBuild target which invokes MSBuild using the Exec task. This will start a new process, and when that process ends, the file locks are released. Example;

    <PropertyGroup>   
         <PrebuildProject>$(SolutionDir)Prebuild\Prebuild.csproj</PrebuildProject>   
    </PropertyGroup>   
    <Target Name="BeforeBuild">   
         <Exec Command="msbuild.exe &quot;$(PrebuildProject)&quot;" />   
    </Target>
    


  • 现在,当您生成依赖项目,在一个新的进程执行的MSBuild运行编译之前。

    Now, when you build the dependent project, it executes MSBuild in a new process before running the compile.

    这篇关于Visual Studio 2008中的自定义锁MSBuild任务组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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