MSBuild 2010 - 如何将 Web 应用程序发布到特定位置 (nant)?

发布于 2024-09-03 11:29:26 字数 1018 浏览 2 评论 0原文

我正在尝试让 MSBuild 2010 将 Web 应用程序发布到特定位置。 我可以让它将部署包发布到特定路径,但部署包随后会添加自己的更改路径。

例如:如果我告诉它发布到 C:\dev\build\Output\Debug 那么实际的 Web 文件最终会在 C:\dev\build\Output\Debug\Archive \Content\C_C\code\app\Source\ControllersViews\obj\Debug\Package\PackageTmp 并且路径的 C_C 部分发生了变化(不确定它如何选择路径的这部分)。

这意味着我不能只从发布位置编写副本脚本。

我现在正在使用这个 nant/msbuild 命令:

  <target name="compile" description="Compiles">
<msbuild project="${name}.sln">

  <property name="Platform" value="Any CPU"/>
  <property name="Configuration" value="Debug"/>
  <property name="DeployOnBuild" value="true"/>
  <property name="DeployTarget" value="Package"/>
  <property name="PackageLocation" value="C:\dev\build\Output\Debug\"/>
  <property name="AutoParameterizationWebConfigConnectionStrings" value="false"/>
  <property name="PackageAsSingleFile" value="false"/>

</msbuild>

关于如何让它将网络文件直接发送到特定位置有什么想法吗?

I'm trying to get MSBuild 2010 to publish a web app to a specific location.
I can get it to publish the deployment package to a particular path, but the deployment package then adds its own path that changes.

For example: if I tell it to publish to C:\dev\build\Output\Debug then the actual web files end up at C:\dev\build\Output\Debug\Archive\Content\C_C\code\app\Source\ControllersViews\obj\Debug\Package\PackageTmp
And the C_C part of the path changes (not sure how it chooses this part of the path).

This means I can't just script a copy from the publish location.

I'm using this nant/msbuild command at the moment:

  <target name="compile" description="Compiles">
<msbuild project="${name}.sln">

  <property name="Platform" value="Any CPU"/>
  <property name="Configuration" value="Debug"/>
  <property name="DeployOnBuild" value="true"/>
  <property name="DeployTarget" value="Package"/>
  <property name="PackageLocation" value="C:\dev\build\Output\Debug\"/>
  <property name="AutoParameterizationWebConfigConnectionStrings" value="false"/>
  <property name="PackageAsSingleFile" value="false"/>

</msbuild>

Any ideas on how to get it to send the web files directly to a specific location?

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

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

发布评论

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

评论(3

↙厌世 2024-09-10 11:29:26
msbuild /t:Build;PipelinePreDeployCopyAllFilesToOneFolder /p:Configuration=Release;_PackageTempDir=C:\temp\somelocation;AutoParameterizationWebConfigConnectionStrings=false MyProject.csproj

对应的 NAnt 脚本:

<msbuild project="MyProject.csproj" target="PipelinePreDeployCopyAllFilesToOneFolder">
  <property name="Configuration" value="Release" />
  <property name="_PackageTempDir" value="C:\temp\somelocation" />
  <property name="AutoParameterizationWebConfigConnectionStrings" value="false" />
</msbuild>

参考文献

另请参阅团队构建:使用 MSDeploy 本地发布

msbuild /t:Build;PipelinePreDeployCopyAllFilesToOneFolder /p:Configuration=Release;_PackageTempDir=C:\temp\somelocation;AutoParameterizationWebConfigConnectionStrings=false MyProject.csproj

Corresponding NAnt script:

<msbuild project="MyProject.csproj" target="PipelinePreDeployCopyAllFilesToOneFolder">
  <property name="Configuration" value="Release" />
  <property name="_PackageTempDir" value="C:\temp\somelocation" />
  <property name="AutoParameterizationWebConfigConnectionStrings" value="false" />
</msbuild>

References

See also Team Build: Publish locally using MSDeploy

℉絮湮 2024-09-10 11:29:26

如果您使用的是 VS2010 Web 应用程序(而不是网站项目),请考虑在项目中设置打包/发布 Web 设置,并在 nant 脚本中构建“项目”目标。

这里有很多有趣的 msdeploy 优点和背景: http://www.hanselman.com/blog/WebDeploymentMadeAwesomeIfYoureUsingXCopyYoureDoingItWrong .aspx

在我的 nant 脚本中,我运行以下 msbuild 命令:

    <if  test="${property::exists('basename')}">
        <exec program="${msbuild.location}" workingdir="${project::get-base-directory()}">
            <arg value="/p:Configuration=${configuration}" />
            <arg value="/logger:ThoughtWorks.CruiseControl.MsBuild.XmlLogger,${msbuild.logger.dll}" if="${nunit.formatter.type == 'Xml'}"/>
            <arg value="/noconsolelogger" if="${nunit.formatter.type == 'Xml'}"/>
            <arg value="${basename}.sln"/>
        </exec>
    </if>

...

    <if  test="${property::exists('basename')}">
        <exec program="${msbuild.location}" workingdir="${project::get-base-directory()}\${basename}">
            <arg value="/p:Configuration=${configuration}" />
            <arg value="/t:Package" />
            <arg value="/logger:ThoughtWorks.CruiseControl.MsBuild.XmlLogger,${msbuild.logger.dll}" if="${nunit.formatter.type == 'Xml'}"/>
            <arg value="/noconsolelogger" if="${nunit.formatter.type == 'Xml'}"/>
            <arg value="${basename}.csproj"/>
        </exec>
    </if>

我的 basename nant 变量给出 VS 解决方案文件 (.sln) 和项目文件 (.csproj) 的名称对于网络应用程序。我碰巧更喜欢项目设置中所示的 zip 文件部署:

Web 应用程序部署的示例包设置

有还有一个怪癖。如果在目标计算机上安装 MSDeploy 版本 2.0,则必须编辑 .deploy.cmd 文件以更改 MSDeploy 版本号,如下所示:

更改

  for /F "usebackq tokens=2*" %%i  in (`reg query "HKLM\SOFTWARE\Microsoft\IIS Extensions\MSDeploy\1" /v InstallPath`) do (

  for /F "usebackq tokens=2*" %%i  in (`reg query "HKLM\SOFTWARE\Microsoft\IIS Extensions\MSDeploy\2" /v InstallPath`) do (

If you are using a VS2010 web application (as opposed to a web site project), consider setting up the Package/Publish Web settings in your project and building the 'Project' target in your nant script.

Lots of juicy msdeploy goodness and background here: http://www.hanselman.com/blog/WebDeploymentMadeAwesomeIfYoureUsingXCopyYoureDoingItWrong.aspx

In my nant scripts, I run the following msbuild commands:

    <if  test="${property::exists('basename')}">
        <exec program="${msbuild.location}" workingdir="${project::get-base-directory()}">
            <arg value="/p:Configuration=${configuration}" />
            <arg value="/logger:ThoughtWorks.CruiseControl.MsBuild.XmlLogger,${msbuild.logger.dll}" if="${nunit.formatter.type == 'Xml'}"/>
            <arg value="/noconsolelogger" if="${nunit.formatter.type == 'Xml'}"/>
            <arg value="${basename}.sln"/>
        </exec>
    </if>

...

    <if  test="${property::exists('basename')}">
        <exec program="${msbuild.location}" workingdir="${project::get-base-directory()}\${basename}">
            <arg value="/p:Configuration=${configuration}" />
            <arg value="/t:Package" />
            <arg value="/logger:ThoughtWorks.CruiseControl.MsBuild.XmlLogger,${msbuild.logger.dll}" if="${nunit.formatter.type == 'Xml'}"/>
            <arg value="/noconsolelogger" if="${nunit.formatter.type == 'Xml'}"/>
            <arg value="${basename}.csproj"/>
        </exec>
    </if>

My basename nant variable gives the name of both the VS solution file (.sln) and the project file (.csproj) for the web application. I happen to prefer the zip-file deployment as shown in my project settings:

Sample Package Settings for Deployment of Web Application

There is one additional quirk. If you install MSDeploy version 2.0 on the target machine, the .deploy.cmd file must be edited to change the MSDeploy version number as follows:

Change

  for /F "usebackq tokens=2*" %%i  in (`reg query "HKLM\SOFTWARE\Microsoft\IIS Extensions\MSDeploy\1" /v InstallPath`) do (

To

  for /F "usebackq tokens=2*" %%i  in (`reg query "HKLM\SOFTWARE\Microsoft\IIS Extensions\MSDeploy\2" /v InstallPath`) do (
北城孤痞 2024-09-10 11:29:26

我认为您使用了错误的属性。请尝试使用 OutDir 属性。

<arg value="/property:OutDir=C:\dev\build\Output\Debug\" />

就个人而言,我直接调用 MsBuild.exe,而不是使用 msbuild 标记:

    <exec program="${MSBuildPath}">
        <arg line='"${ProjectFile}"' />
        <arg value="/target:_CopyWebApplication" />
        <arg value="/property:OutDir=${LocalDeployPath}\" />
        <arg value="/property:WebProjectOutputDir=${LocalDeployPath}" />
        <arg value="/property:Configuration=${SolutionConfiguration}" />
        <arg value="/verbosity:normal" />
        <arg value="/nologo" />
    </exec>

MSBuildPath - MsBuild.exe 的路径(允许您定位所需的任何框架版本)

ProjectFile -项目文件的相对路径

LocalDeployPath - 将输出所有内容的本地文件夹。您的复制脚本也将使用它作为源目录。

解决方案配置 - 发布、调试

I think you're using the wrong property. Try the OutDir property instead.

<arg value="/property:OutDir=C:\dev\build\Output\Debug\" />

Personally, I call MsBuild.exe directly instead of using the msbuild tag:

    <exec program="${MSBuildPath}">
        <arg line='"${ProjectFile}"' />
        <arg value="/target:_CopyWebApplication" />
        <arg value="/property:OutDir=${LocalDeployPath}\" />
        <arg value="/property:WebProjectOutputDir=${LocalDeployPath}" />
        <arg value="/property:Configuration=${SolutionConfiguration}" />
        <arg value="/verbosity:normal" />
        <arg value="/nologo" />
    </exec>

MSBuildPath - The path to MsBuild.exe (allows you to target any framework version you want)

ProjectFile - The relative path to your project file

LocalDeployPath - The local folder where everthing will be outputed. Your copy script will use also use this as the source directory.

SolutionConfiguration - Release, Debug

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