MS Deploy 可以打包并转换,但不能部署吗?

发布于 2024-09-17 23:13:29 字数 433 浏览 6 评论 0原文

使用 .NET 4.0 中的 msbuild,我可以使用“Package”目标构建 Web 项目,并且它可以很好地将包放入 zip 文件中。但是,当我查看其中的 web.config 时,它没有转换,它有“$(ReplacableToken_Web_SiteConnection-Web.config Connection String_0)”

我可以运行“TransformWebConfig”目标,它将进行正确的转换,但只是在它自己的筒仓。

我还可以运行“Build”目标并传递“DeployOnBuild=True;DeployTarget=MSDeployPublish”属性,它将在我的服务器上部署包并完成正确的 web.config 转换。

但是,如果我想手动将包部署到服务器,如何使用“TransformWebConfig”创建“包”,以便 zip 文件中包含最终的 web.config?

Using msbuild in .NET 4.0, I can build web project with the "Package" target, and it does a nice job of putting the package in a zip file. But, when I look at the web.config in there, it's not transformed, it has "$(ReplacableToken_Web_SiteConnection-Web.config Connection String_0)"

I can run the "TransformWebConfig" target and it will do the proper transform, but just in its own silo.

I can also run the "Build" target and pass the "DeployOnBuild=True;DeployTarget=MSDeployPublish" properties and it will deploy the package on my server with the proper web.config transform done.

But, if I want to manually deploy the package to the server, how do I do a "Package" with a "TransformWebConfig" so that the zip file has the final web.config in there?

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

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

发布评论

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

评论(2

皓月长歌 2024-09-24 23:13:30

如果您想避免这种情况发生,那么您需要在构建中设置一个属性。您可以通过两种方式执行此操作

  1. 编辑项目文件
  2. 创建 .wpp.targets 文件

我建议#2。对于这种情况,在项目文件所在的同一目录中创建一个名为 {ProjectName}.wpp.targets 的新文件,其中 {ProjectName} 是项目的名称。然后,您应该在此文件中放置以下内容。

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
         ToolsVersion="4.0">
  <PropertyGroup>
    <AutoParameterizationWebConfigConnectionStrings>false</AutoParameterizationWebConfigConnectionStrings>
  </PropertyGroup>
</Project>

在本例中,您设置的属性 AutoParameterizationWebConfigConnectionStrings 会告诉 Web 发布管道不要在连接字符串的 web.config 中插入那些 {} 占位符。

If you want to skip this from happening then you need to set a property in your build. You can do this in two ways

  1. Edit your project file
  2. Create a .wpp.targets file

I would recommend #2. For this case create a new file in the same directory as your project file with the name {ProjectName}.wpp.targets where {ProjectName} is the name of your project. Then inside of this file you should place the following contents.

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
         ToolsVersion="4.0">
  <PropertyGroup>
    <AutoParameterizationWebConfigConnectionStrings>false</AutoParameterizationWebConfigConnectionStrings>
  </PropertyGroup>
</Project>

In this case you are setting the property AutoParameterizationWebConfigConnectionStrings which tells the Web Publishing Pipeline to not insert those {} placeholders in the web.config for the connection strings.

埖埖迣鎅 2024-09-24 23:13:30

我们这样做的方法是在打包之前修改项目构建以进行转换。

目标称为 TransformXml,是 Microsoft.Web.Publishing.Tasks.dll 的一部分,

在您自己的目标中,

<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll"  /> 

但它将包含在默认的 VS C# 构建中。

<TransformXml Source="web.config" Transform="web.release.config" Destination="$(DeployPath)\web.config" />

对我们来说也是如此。

使用正确的 ItemGroup(最有可能是“内容”)设置这些路径,并确保在调用 .csproj 中的 Package 之前触发目标,并且构建输出将像平常一样包含“Web.config”,其中包含正确变换的值。

或者(我们已将其用于需要满足所有人需求的包),您可以使用该技巧来完成所有转换并将它们包含在最终包中。

然后您手动调用 Msdeploy 并使用其跳过和替换指令(忘记了技术术语)仅在部署时输出正确的指令

假设您的包中有一个 web.usethisone.config ,看起来像

-skip:objectname=filepath,absolutepath=web\..*\.config 

-replace:objectName=filepath,match=.*web\.usethisone\.config,replace=web.config

The way we do this is by modifiying the project build to do the transform prior to packaging it up.

The Target is call TransformXml and is a part of Microsoft.Web.Publishing.Tasks.dll

In your own targets its

<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll"  /> 

But it will be included in a default VS C# build.

So

<TransformXml Source="web.config" Transform="web.release.config" Destination="$(DeployPath)\web.config" />

Does the trick for us.

Set up those paths with the right ItemGroup ("content" most likely) and make sure that target gets fired prior to the call to Package in your .csproj, and the build output will contain a "Web.config" like normal, with the right transformed values.

Alternatively (we've used this for packages that need to be everything to everyone), you can use that trick to do ALL the transforms and include each of them in the final package.

Then you call Msdeploy manually and use its skip and replace directives (forgot the technical term) to only output the right one at deploy-time

Assuming you have a web.usethisone.config in your package, that looks like

-skip:objectname=filepath,absolutepath=web\..*\.config 

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