Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>(<strong>Edit:</strong> <a href="https://stackoverflow.com/users/105999/sayed-ibrahim-hashimi">Sayed Ibrahim Hashimi</a>, who literally <a href="http://rads.stackoverflow.com/amzn/click/0735626286" rel="nofollow noreferrer">wrote the book</a> on msbuild, suggests the <a href="http://msdn.microsoft.com/en-us/library/microsoft.build.utilities.appdomainisolatedtask%28VS.80%29.aspx" rel="nofollow noreferrer">AppDomainIsolatedTask</a> class for a better approach)</p> <p>I've managed to solve this one myself...</p> <p>Found this <a href="http://www.netframeworkdev.com/msbuild/msbuild-doesnt-release-custom-tasks-assemblies-after-compile-22497.shtml" rel="nofollow noreferrer">forum post from Dan Moseley</a>, one of the MSBuild developers from Microsoft:</p> <blockquote> <p>Hi there,</p> <p>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.</p> <p>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 &lt;> as an external tool in VS.</p> <p>Dan<br> developer on msbuild<br> DanMoseley - MSFT </p> </blockquote> <p>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.</p> <ul> <li><p>create a new MSBuild project (a .csproj or similar) which overrides the 'Build' Target and performs your custom actions, eg;</p> <pre><code>&lt;!-- fragment of Prebuild.csproj --&gt; &lt;Target Name="Build"&gt; &lt;BuildOrmLayerTask Repository="$(Repository)" /&gt; &lt;/Target&gt; </code></pre></li> <li><p>Add it to visual studio if you want, but use Configuration Manager to make sure it is <em>not</em>built in any configuration. Just let VS take care of source control and suchlike, not building.</p></li> <li><p>Edit the .csproj file of the project that depends on <code>Prebuild.csproj</code>. Add a <code>BeforeBuild</code> target which invokes MSBuild using the <code>Exec</code> task. This will start a new process, and when that process ends, the file locks are released. Example;</p> <pre><code>&lt;PropertyGroup&gt; &lt;PrebuildProject&gt;$(SolutionDir)Prebuild\Prebuild.csproj&lt;/PrebuildProject&gt; &lt;/PropertyGroup&gt; &lt;Target Name="BeforeBuild"&gt; &lt;Exec Command="msbuild.exe &amp;quot;$(PrebuildProject)&amp;quot;" /&gt; &lt;/Target&gt; </code></pre></li> </ul> <p>Now, when you build the dependent project, it executes MSBuild in a new process before running the compile.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload