VS2010 Web Publish 命令行版文件系统部署

发布于 2024-09-29 15:30:21 字数 899 浏览 8 评论 0原文

各位,

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

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

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

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

我知道我可以使用 nAnt 任务或 rake 脚本来复制此功能,但我想使用此机制来完成此操作,因此我不会重复自己。

我对此进行了更多调查,并且找到了这些链接,但没有一个能够干净地解决它:

提前致谢!

Folks,

In a nutshell, I want to replicate this dialog:
alt text

It's a Visual Studio 2010 ASP.Net MVC project. If I execute this command, I get all the files I want, including the transformed web.configs in the "C:\ToDeploy" directory.

I want to replicate this on the command line so I can use it for a QA environment build.

I've seen various articles on how to do this on the command line for Remote Deploys, but I just want to do it for File System deploys.

I know I could replicate this functionality using nAnt tasks or rake scripts, but I want to do it using this mechanism so I'm not repeating myself.

I've investigated this some more, and I've found these links, but none of them solve it cleanly:

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

谷夏 2024-10-06 15:30:21

好吧,终于弄清楚了。

您需要的命令行是:

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

Ok, finally figured this out.

The command line you need is:

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

You can change where the project outputs to by adding a property of outdir=c:\wherever\ in the /p: section.

This will create the output at:

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

You can then copy those files from the above directory using whatever method you'd like.

I've got this all working as a ruby rake task using Albacore. I am trying to get it all done so I can actually put it as a contribution to the project. But if anyone wants the code before that, let me know.

Another wrinkle I found was that it was putting in Tokenized Parameters into the Web.config. If you don't need that feature, make sure you add:

/p:AutoParameterizationWebConfigConnectionStrings=false
只等公子 2024-10-06 15:30:21

我想我应该发布我找到的另一个解决方案,我已经更新了这个解决方案以包含日志文件。

这类似于从命令行发布 Web 应用程序 ,但只是清理并添加了日志文件。另请查看原始来源 http://www.digitallycreated.net/Blog/59/locally-publishing-a-vs2010-asp.net-web-application-using-msbuild

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

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=

通过在 标记下添加以下 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) 从命令行发布 Web 应用程序

3) 通过命令行构建 Visual Studio 项目

I thought I'd post a another solution that I found, I've updated this solution to include a log file.

This is similar to Publish a Web Application from the Command Line, but just cleaned up and added log file. also check out original source http://www.digitallycreated.net/Blog/59/locally-publishing-a-vs2010-asp.net-web-application-using-msbuild

Create an MSBuild_publish_site.bat (name it whatever) in the root of your web application project

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=

Update your Web Application project file MyWebBasedApp.csproj by adding the following xml under the <Import Project= tag

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

this works better for me than other solutions.

Check out the following for more info:

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

北方的韩爷 2024-10-06 15:30:21

我的带有 Web.config 转换CCNET 解决方案:

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

My solution for CCNET with the Web.config transformation:

<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>
烂柯人 2024-10-06 15:30:21

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

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

On VS2012 and above, you can refer to existing publish profiles on your project with msbuild 12.0, this would be equivalent to right-click and publish... selecting a publish profile ("MyProfile" on this example):

msbuild C:\myproject\myproject.csproj "/P:DeployOnBuild=True;PublishProfile=MyProfile"
吃颗糖壮壮胆 2024-10-06 15:30:21

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

但是,它可以在没有安装 Visual Studio 的情况下运行! (请参阅更新)。
我还没有检查是否可以从 Visual Studio Express 2012 获取 Web 安装所需的所有内容。

I've got a solution for Visual Studio 2012: https://stackoverflow.com/a/15387814/2164198

However, it works with no Visual Studio installed at all! (see UPDATE).
I didn't checked yet whether one can get all needed stuff from Visual Studio Express 2012 for Web installation.

寄风 2024-10-06 15:30:21

受 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 文件夹中

A complete msbuild file with inspiration from CubanX

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

This places the published website in the Web..\build\Release folder

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文