asp.net-mvc 如何使用 MsBuild MsDeployPublish 定位本地文件系统?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9169341/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use MsBuild MsDeployPublish to target local file system?
提问by DuckMaestro
I'm trying to replicate the Visual Studio 2010 "Publish..." command (applicable to Web Application projects) where I would in the UI choose Publish Method: "File System".
我正在尝试复制 Visual Studio 2010“发布...”命令(适用于 Web 应用程序项目),我将在 UI 中选择发布方法:“文件系统”。
My attempt at this is...
我在这方面的尝试是...
%msbuild% /t:MsDeployPublish /property:MsDeployServiceUrl="file:///d:\MyDeploymentFolder";MsDeployPublishMethod="File System" "d:\MySourceFolder\Project.csproj"
%msbuild% /t:MsDeployPublish /property:MsDeployServiceUrl="file:///d:\MyDeploymentFolder";MsDeployPublishMethod="文件系统" "d:\MySourceFolder\Project.csproj"
... and having tried a method of "FileSystem", "File System", "Local", and a few others.
...并尝试了“文件系统”、“文件系统”、“本地”和其他一些方法。
The error I get implies that MsDeploy is still trying to push to an IIS server:
我得到的错误意味着 MsDeploy 仍在尝试推送到 IIS 服务器:
"D:\MySourceFolder\Project.csproj" (MsDeployPub
lish target) (1) ->
(MSDeployPublish target) ->
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web
.Publishing.targets(3847,5): error : Web deployment task failed.(The metabase k
ey '/lm/w3svc' could not be found.) [D:\MySourceFolder\Project.csproj]
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.P
ublishing.targets(3847,5): error : \r [D:\MySourceFolder\Project.csproj]
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.P
ublishing.targets(3847,5): error : The metabase key '/lm/w3svc' could not be fo
und.\r [D:\MySourceFolder\Project.csproj]
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.P
ublishing.targets(3847,5): error : Unable to access the IIS configuration syste
m. Please make sure you have IIS 7 (or later) installed.\r [D:\MySourceFolder\Project.csproj]
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.P
ublishing.targets(3847,5): error : Retrieving the COM class factory for compone
nt with CLSID {2B72133B-3F5B-4602-8952-803546CE3344} failed due to the followin
g error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REG
DB_E_CLASSNOTREG)). [D:\MySourceFolder\Project.csproj]
How can I target the file system for deployment, as Visual Studio normally lets me in the GUI?
我如何才能将文件系统作为部署目标,因为 Visual Studio 通常让我进入 GUI?
回答by Richard Szalay
As per my answer from Using MSBuild, how do I build an MVC4 solution from the command line (applying Web.config transformations in the process) and output to a folder?
根据我在Using MSBuild 中的回答,如何从命令行构建 MVC4 解决方案(在此过程中应用 Web.config 转换)并输出到文件夹?
msbuild ProjectFile.csproj /p:Configuration=Release ^
/p:Platform=AnyCPU ^
/t:WebPublish ^
/p:WebPublishMethod=FileSystem ^
/p:DeleteExistingFiles=True ^
/p:publishUrl=c:\output
Or if you are building the solution file:
或者,如果您正在构建解决方案文件:
msbuild Solution.sln /p:Configuration=Release ^
/p:DeployOnBuild=True ^
/p:DeployDefaultTarget=WebPublish ^
/p:WebPublishMethod=FileSystem ^
/p:DeleteExistingFiles=True ^
/p:publishUrl=c:\output
You can also target the project via the solutionusing the /t:SolutionFolder/Project:Targetsyntax:
您还可以使用以下语法通过解决方案定位项目/t:SolutionFolder/Project:Target:
msbuild Solution.sln /t:SolutionFolder/ProjectFile:WebPublish ^
/p:Configuration=Release ^
/p:WebPublishMethod=FileSystem ^
/p:DeleteExistingFiles=True ^
/p:publishUrl=c:\output
回答by Todd Menier
I gave up trying to get MSBuild to copy deployable web files (and not do anything else but that), so I scripted it in PowerShell and am really happy with the result. Much faster than anything I tried through MSBuild. Here's the gist (literally):
我放弃了让 MSBuild 复制可部署的 Web 文件的尝试(除此之外什么都不做),所以我在 PowerShell 中编写了它的脚本,并且对结果非常满意。比我通过 MSBuild 尝试的任何东西都快得多。这是要点(字面意思):
function copy-deployable-web-files($proj_path, $deploy_dir) {
# copy files where Build Action = "Content"
$proj_dir = split-path -parent $proj_path
[xml]$xml = get-content $proj_path
$xml.Project.ItemGroup | % { $_.Content } | % { $_.Include } | ? { $_ } | % {
$from = "$proj_dir$_"
$to = split-path -parent "$deploy_dir$_"
if (!(test-path $to)) { md $to }
cp $from $to
}
# copy everything in bin
cp "$proj_dir\bin" $deploy_dir -recurse
}
回答by Jesse
I don't think you are being specific enough with what you are telling msbuild.
我认为您对 msbuild 所说的内容不够具体。
Pulled this out of one of my bookmarks on the subject, hopefully it will help: http://www.digitallycreated.net/Blog/59/locally-publishing-a-vs2010-asp.net-web-application-using-msbuild
从我关于该主题的书签之一中取出它,希望它会有所帮助:http: //www.digitallycreated.net/Blog/59/locally-publishing-a-vs2010-asp.net-web-application-using-msbuild

