Visual Studio 2008 锁定自定义 MSBuild 任务程序集 [英] Visual Studio 2008 locks custom MSBuild Task assemblies

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

问题描述

我正在开发一个自定义 MSBuild 任务,该任务构建一个 ORM 层,并使用它在一个项目中.我受到 Visual Studio 坚持 MSBuild 任务 DLL 并且不放手的行为的阻碍.

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?

推荐答案

( Ibrahim Hashimi 说,他在 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...

发现这个论坛来自 Microsoft MSBuild 开发人员之一 Dan Moseley 的帖子:

你好,

不幸的是,这是因为 MSBuild 在主应用程序域.CLR 不允许卸载程序集来自应用程序域,因为这允许对其进行重要优化部分.

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 上的开发人员
丹莫斯利 - 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,但使用配置管理器确保它内置在任何配置中.只需让 VS 负责源代码控制等,而不是构建.

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

    编辑依赖于 Prebuild.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)PrebuildPrebuild.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天全站免登陆