Deploying .Net Core app fails because dll is locked

41 Views Asked by At

I'm having a deployment issue. With a .Net 6 application, it frequently fails to deploy because the main dll is locked. According to the documentation, I can use an app_offline file to manage this. How to deploy and manage this file was a real problem, but even after I finally for it working, it doesn't solve the problem. For example, as a test I added the app_offline file to the site. The site now displays an under maintenance message. But after removing the file, the site wouldn't restart and it required a fair amount of manual intervention. What is the expected way to deal with the base issue - that deploying to a running site fails because the site wont release the ddl to replace it with the new version?

1

There are 1 best solutions below

0
Ethan Schofer On BEST ANSWER

I found the issue. This is how you need to deploy to an on-prem ISS instance with newer .Net versions. You enable it by adding some stuff to the web.config. In .Net 6, ShadowCopy is experimental, so you add:

<aspNetCore processPath="dotnet" arguments=".\KhovOptimizely.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess">
    <handlerSettings xdt:Transform="InsertIfMissing">
        <handlerSetting name="experimentalEnableShadowCopy" value="true"/>
        <handlerSetting name="shadowCopyDirectory" value="D:\Websites\KHOV_Replatform\ShadowCopyDirectory\"/>
    </handlerSettings>
</aspNetCore>

But starting in .Net 7, its no longer experimental. So you can set it up like so:

<aspNetCore processPath="dotnet" arguments=".\KhovOptimizely.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess">
    <handlerSettings xdt:Transform="InsertIfMissing">
        <handlerSetting name="enableShadowCopy" value="true"/>
        <handlerSetting name="shadowCopyDirectory" value="D:\Websites\KHOV_Replatform\ShadowCopyDirectory\"/>
    </handlerSettings>
</aspNetCore>

And the good part. If you are deploying a .Net 6 app to a server where .Net 6 AND .Net 7 or 8 is ALSO installed, you need both, even if your app is .Net 6:

<aspNetCore processPath="dotnet" arguments=".\KhovOptimizely.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess">
    <handlerSettings xdt:Transform="InsertIfMissing">
        <handlerSetting name="experimentalEnableShadowCopy" value="true"/>
        <handlerSetting name="enableShadowCopy" value="true"/>
        <handlerSetting name="shadowCopyDirectory" value="D:\Websites\KHOV_Replatform\ShadowCopyDirectory\"/>
    </handlerSettings>
</aspNetCore>