【问题标题】:VS2010 Web Publish command line version of File System deployVS2010 Web Publish命令行版文件系统部署
【发布时间】:2011-05-01 01:57:47
【问题描述】:

伙计们,

简而言之,我想复制这个对话框:

这是一个 Visual Studio 2010 ASP.Net MVC 项目。如果我执行这个命令,我会得到我想要的所有文件,包括“C:\ToDeploy”目录中转换后的 web.configs。

我想在命令行上复制它,以便将其用于 QA 环境构建。

我看过各种文章,介绍如何在远程部署的命令行上执行此操作,但我只想为文件系统部署执行此操作。

我知道我可以使用 nAnt 任务或 rake 脚本来复制此功能,但我想使用此机制来实现,所以我不会重复自己。

我对此进行了更多调查,并找到了这些链接,但没有一个能彻底解决:

提前致谢!

【问题讨论】:

    标签: visual-studio-2010 command-line msdeploy web-publishing msbuild-wpp


    【解决方案1】:

    好的,终于明白了。

    你需要的命令行是:

    msbuild path/to/your/webdirectory/YourWeb.csproj /p:Configuration=Debug;DeployOnBuild=True;PackageAsSingleFile=False
    

    您可以通过在 /p: 部分添加 outdir=c:\wherever\ 属性来更改项目的输出位置。

    这将在以下位置创建输出:

    path/to/your/webdirectory/obj/Debug/Package/PackageTmp/
    

    然后,您可以使用任何您喜欢的方法从上述目录中复制这些文件。

    我已经使用 Albacore 将这一切作为 ruby​​ rake 任务工作。我正在努力完成这一切,这样我实际上可以把它作为对项目的贡献。但如果有人想要在那之前的代码,请告诉我。

    我发现的另一个问题是它将标记化参数放入 Web.config。如果您不需要该功能,请确保添加:

    /p:AutoParameterizationWebConfigConnectionStrings=false
    

    【讨论】:

    • 不幸的是,这会复制整个包。我认为您需要使用 MS Web Deploy 来仅复制更改的文件。
    • 为了完整性,OutDir 属性必须以斜杠结尾(否则 MSBuild 错误)。所以你的建议应该是outdir=c:\wherever\
    • 另外,您可以使用 Package 目标来代替 /p:DeployOnBuild=True/t:Package。对我有用,而且 PackageAsSingleFileAutoParameterizationWebConfigConnectionStrings 参数也受到尊重。
    • @Jakub 我更新了答案以反映 OutDir 评论,谢谢!
    【解决方案2】:

    我想我会发布我找到的另一个解决方案,我已更新此解决方案以包含一个日志文件。

    这类似于Publish a Web Application from the Command Line,但只是清理并添加了日志文件。另请查看原始来源http://www.digitallycreated.net/Blog/59/locally-publishing-a-vs2010-asp.net-web-application-using-msbuild

    在您的 Web 应用程序项目的根目录中创建一个 MSBuild_publish_site.bat(随便命名)

    set msBuildDir=%WINDIR%\Microsoft.NET\Framework\v4.0.30319
    set destPath=C:\Publish\MyWebBasedApp\
    
    :: clear existing publish folder
    RD /S /Q "%destPath%"
    
    call %msBuildDir%\msbuild.exe  MyWebBasedApp.csproj "/p:Configuration=Debug;PublishDestination=%destPath%;AutoParameterizationWebConfigConnectionStrings=False" /t:PublishToFileSystem /l:FileLogger,Microsoft.Build.Engine;logfile=Manual_MSBuild_Publish_LOG.log
    
    set msBuildDir=
    set destPath=
    

    通过在<Import Project= 标记下添加以下 xml 来更新您的 Web 应用程序项目文件 MyWebBasedApp.csproj

    <Target Name="PublishToFileSystem" DependsOnTargets="PipelinePreDeployCopyAllFilesToOneFolder">
    <Error Condition="'$(PublishDestination)'==''" Text="The PublishDestination property must be set to the intended publishing destination." />
        <MakeDir Condition="!Exists($(PublishDestination))" Directories="$(PublishDestination)" />
    
        <ItemGroup>
            <PublishFiles Include="$(_PackageTempDir)\**\*.*" />
        </ItemGroup>
    
        <Copy SourceFiles="@(PublishFiles)" DestinationFiles="@(PublishFiles->'$(PublishDestination)\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="True" />
    </Target>
    

    这比其他解决方案更适合我。

    查看以下内容了解更多信息:

    1) http://www.digitallycreated.net/Blog/59/locally-publishing-a-vs2010-asp.net-web-application-using-msbuild

    2)Publish a Web Application from the Command Line

    3)Build Visual Studio project through the command line

    【讨论】:

      【解决方案3】:

      我的 CCNET 解决方案与 Web.config 转换

      <tasks>
          <msbuild>
              <executable>C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe</executable>
              <workingDirectory>E:\VersionesCC\Trunk_4\SBatz\Gertakariak_Orokorrak\GertakariakMS\Web</workingDirectory>
              <projectFile>GertakariakMSWeb2.vbproj</projectFile>
              <targets>Build</targets>
              <timeout>600</timeout>
              <logger>C:\Program Files\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MSBuild.dll</logger>
              <buildArgs>
                  /noconsolelogger /p:Configuration=Release /v:diag
                  /p:DeployOnBuild=true
                  /p:AutoParameterizationWebConfigConnectionStrings=false
                  /p:DeployTarget=Package
                  /p:_PackageTempDir=E:\Aplicaciones\GertakariakMS2\Web
              </buildArgs>
              </msbuild>
      </tasks>
      

      【讨论】:

        【解决方案4】:

        在 VS2012 及更高版本上,您可以使用 msbuild 12.0 引用现有的publish profiles on your project,这相当于右键单击并发布...选择发布配置文件(本例中为“MyProfile”):

        msbuild C:\myproject\myproject.csproj "/P:DeployOnBuild=True;PublishProfile=MyProfile"
        

        【讨论】:

          【解决方案5】:

          我有 Visual Studio 2012 的解决方案:https://stackoverflow.com/a/15387814/2164198

          但是,它完全可以在没有安装 Visual Studio 的情况下工作! (参见更新)。 我还没有检查是否可以从 Visual Studio Express 2012 中获得所有需要的东西以进行 Web 安装。

          【讨论】:

            【解决方案6】:

            灵感来自 CubanX 的完整 msbuild 文件

                <Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
                <Target Name="Publish">
                    <RemoveDir Directories="..\build\Release\Web\"
                                 ContinueOnError="true" />        
                   <MSBuild Projects="TheWebSite.csproj"
                            Targets="ResolveReferences;_CopyWebApplication"
                            Properties="Configuration=Release;WebProjectOutputDir=..\build\Release\Web;OutDir=..\build\Release\Web\bin\"
                    />  
                </Target>
                <Target
                    Name="Build"
                    DependsOnTargets="Publish;">
                </Target>   
            </Project>
            

            这会将发布的网站放在 Web..\build\Release 文件夹中

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 2013-09-30
              • 2012-08-15
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2011-06-08
              相关资源
              最近更新 更多