.NET Core 锁定文件 [英] .NET Core locking files

查看:29
本文介绍了.NET Core 锁定文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 ASP.NET Core 应用程序.我通过运行命令

I have a ASP.NET Core app. I run the application by running the command

dotnet run

当我构建这个 ASP.NET Core 应用程序时,我在五分之一的情况下看到以下错误.

I'm seeing the following error in one out of five situations when I build this ASP.NET Core app.

C:...error CS2012: 无法打开 'C:...inDebug etcoreapp1.0AAA.Web.dll' 进行写入 -- '进程无法访问文件 'C:...inDebug etcoreapp1.0AAA.Web.dll',因为它正被另一个进程使用.'

C:...error CS2012: Cannot open 'C:...inDebug etcoreapp1.0AAA.Web.dll' for writing -- 'The process cannot access the file 'C:...inDebug etcoreapp1.0AAA.Web.dll' because it is being used by another process.'

除了上述问题之外,我还没有看到我在 CSHTML 文件中所做的任何更新.我必须停止 dotnet run 命令,再次构建应用程序,然后运行 ​​dotnet run 命令.

In addition to the above issue, I also see no updates that I make in the CSHTML file. I have to stop the dotnet run command, build the app again and then run the dotnet run command.

我该如何解决这些问题?

How can I fix these issues?

推荐答案

在 IIS 中运行 aspnetcore 应用程序时,这也可能有所帮助.

This may also help when running your aspnetcore app in IIS.

将以下内容添加到您的 csproj:

Add the following to your csproj:

  <Target Name="PreBuild" BeforeTargets="PreBuildEvent">
    <Exec Command="echo &quot;App Offline&quot; /a &gt; &quot;$(ProjectDir)app_offline.htm&quot;" />
  </Target>

  <Target Name="PostBuild" AfterTargets="PostBuildEvent">
    <Exec Command="del &quot;$(ProjectDir)app_offline.htm&quot;" />
  </Target>

这篇关于.NET Core 锁定文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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