How to use MsBuild MsDeployPublish to target local file system?

后端 未结 3 1733
半阙折子戏
半阙折子戏 2021-01-29 19:38

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\".

相关标签:
3条回答
  • 2021-01-29 20:18

    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):

    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
    }
    
    0 讨论(0)
  • 2021-01-29 20:36

    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?

    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 solution using the /t:SolutionFolder/Project:Target syntax:

    msbuild Solution.sln /t:SolutionFolder/ProjectFile:WebPublish ^
                         /p:Configuration=Release ^ 
                         /p:WebPublishMethod=FileSystem ^
                         /p:DeleteExistingFiles=True ^
                         /p:publishUrl=c:\output
    
    0 讨论(0)
  • 2021-01-29 20:37

    I don't think you are being specific enough with what you are telling 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

    0 讨论(0)
提交回复
热议问题