2012-02-07 16 views
23

Tôi đang cố gắng sao chép Visual Studio 2010 "Xuất bản ..." lệnh (áp dụng cho các dự án ứng dụng Web), nơi tôi sẽ trong giao diện người dùng chọn Phương thức xuất bản: "Hệ thống tệp".Làm thế nào để sử dụng MsBuild MsDeployPublish để nhắm mục tiêu hệ thống tệp cục bộ?

nỗ lực của tôi ở đây là ...

% msbuild%/t: MsDeployPublish/bất động sản: MsDeployServiceUrl = "file: /// d: \ MyDeploymentFolder"; MsDeployPublishMethod = "File System" "d : \ MySourceFolder \ Project.csproj "

... và đã thử phương pháp" FileSystem "," File System "," Local "và một vài cách khác.

Các lỗi tôi nhận được ngụ ý rằng MsDeploy vẫn đang cố gắng đẩy đến một máy chủ 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] 

Làm thế nào tôi có thể nhắm mục tiêu các hệ thống tập tin cho việc triển khai, như Visual Studio thường cho phép tôi trong GUI?

+0

Xem [Làm thế nào để xuất bản ứng dụng web đến một địa điểm cụ thể (Nant)?] (Http://stackoverflow.com/questions/2928595) –

Trả lời

80

Như mỗi câu trả lời của tôi từ 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?

msbuild ProjectFile.csproj /p:Configuration=Release^
          /p:Platform=AnyCPU^
          /t:WebPublish^
          /p:WebPublishMethod=FileSystem^
          /p:DeleteExistingFiles=True^
          /p:publishUrl=c:\output 

Hoặc nếu bạn đang xây dựng các tập tin giải pháp:

msbuild Solution.sln /p:Configuration=Release^
        /p:DeployOnBuild=True^
        /p:DeployDefaultTarget=WebPublish^
        /p:WebPublishMethod=FileSystem^
        /p:DeleteExistingFiles=True^
        /p:publishUrl=c:\output 
+6

Đây là Chén thánh của tòa nhà tệp csproj web. – Matthew

+1

Nếu bạn đang xây dựng với Visual Studio 2013, hãy thử thêm '/ p: VisualStudioVersion = 12.0' nếu bạn gặp lỗi khi nói rằng mục tiêu' WebPublish' không tồn tại. – Matthew

+0

Trong trường hợp bạn đang tìm kiếm máy chủ xây dựng (Teamcity), chỉ định trong trường 'Targets:': Xây dựng lại WebPublish và kiểm tra câu trả lời này để WebPublishing hoạt động trên máy chủ đại lý mà không cần cài đặt studio trực quan: http: // stackoverflow .com/a/24245360/2901207 – CularBytes

2

Tôi đã từ bỏ việc cố gắng để MSBuild sao chép các tệp web có thể triển khai (và không làm gì khác ngoài điều đó), vì vậy tôi đã viết kịch bản đó trong PowerShell tôi thực sự hài lòng với kết quả. Nhanh hơn bất cứ thứ gì tôi đã thử qua MSBuild. Dưới đây là các ý chính (literally):

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 
}