将.Net核心发布到IIS-进程无法访问文件

将.Net核心发布到IIS-进程无法访问文件,iis,asp.net-core,.net-core,Iis,Asp.net Core,.net Core,我正在使用FTP将我的ASP.Net Core 2.0应用程序部署到远程服务器。远程服务器正在使用IIS 8。当我发布应用程序时,出现以下错误 Unable to add 'Project.dll' to the Web site. The process cannot access the file because it is being used by another process (550). 我能够绕过这个问题,首先在发布目录上手动创建一个app_offline.htm,然后通过V

我正在使用FTP将我的ASP.Net Core 2.0应用程序部署到远程服务器。远程服务器正在使用IIS 8。当我发布应用程序时,出现以下错误

Unable to add 'Project.dll' to the Web site.  The process cannot access the file because it is being used by another process (550).
我能够绕过这个问题,首先在发布目录上手动创建一个
app_offline.htm
,然后通过Visual Studio 2017发布我的应用程序


我在想,有没有更简单的方法?或者有没有一种简单的方法可以编写脚本,以便在发布之前自动创建app_offline?然后在发布后删除

任何好奇的人,我放弃了依靠VS发布我的.NET核心项目。我现在正在使用我创建的和_PublishToWeb.bat脚本来完成任务

我首先在我的发布文件夹的根目录上创建了一个名为
\u app.offline.htm
的文件。然后,当我需要发布时,我运行下面的脚本

此脚本执行以下操作:
1.将.NET核心项目构建到特定文件夹,我们称之为“\u dist”文件夹。
2.连接到我的ftp服务器/发布文件夹,并将“\u app\u offline.html”重命名为“app\u offline.html”,以便服务器脱机。
3.将_dist文件夹与发布文件夹同步。
4.完成后,将“app_offline.htm”更改为“_app_offline.html”,以便重新启动网站

\u PublishToWeb.bat

echo off
echo Publishing to ProjectName (Optional)
set ProjectRemoteFolder=RemoteFolderName
set ConnectionString=ftp://username:password@serverIp:serverPort
set WinSCP="path to WinSCP.com"
set ProjectDistPath="a folder where dotnet publish will build the project to"
set WebAppProject="path of the project. dotnet publish will run here"

rem Build project and put it in to distribution folder
cd %WebAppProject%
dotnet publish -c Release -o %ProjectDistPath%

rem Connect to FTP and synchronize folder
%WinSCP% /command "open %ConnectionString%/%ProjectRemoteFolder%/" "mv _app_offline.htm app_offline.htm" "synchronize remote %ProjectDistPath%" "mv app_offline.htm _app_offline.htm" "exit"

rem pause

我确信有更好的解决方案,但到目前为止,这对我来说一直很有效。

您做了哪些功能?是否使用项目打开文件?确保你处理了这个物体。嗯。。。有趣的一点。否,没有打开/关闭文件。我相信这会通过ftp发生在所有asp核心项目上。当我在谷歌搜索时,这似乎是一个常见的问题,然而,我只是还没有找到一个合适的解决方案。伟大的解决方案,Visual Studio发布到ftp对我们来说根本不起作用。。非常感谢。这个关于.bat的变通方法很不方便,因为有人需要复制缩小的ccs、js、资产和其他东西。@LapenkovVladimir缩小的css、js等应该在构建时完成,并且应该在分发文件夹中。如果没有,您可以修改.bat文件,以便在执行同步之前从其他位置复制缩小的css、js等文件。这只是一种方法,如果您有更好的选择,请共享。@FerX32、assets和js默认位于wwroot文件夹中,而不是在distrib中folder@LapenkovVladimirwwwroot文件夹位于dist文件夹内(假设发布生成成功)。因此,wwwroot中的那些静态文件已经设计为同步。我知道,因为我一直在用它们。