【发布时间】:2013-02-13 13:33:35
【问题描述】:
我目前正在尝试在我的生产服务器上启动并运行我的部署过程。目前我正在使用网络部署和发布配置文件来实现这一点,并且除了更新连接字符串以适应生产服务器之外,我的一切工作正常。
我正在使用:
msbuild myProj.csproj /p:DeployOnBuild=true;PublishProfile=myProfile;Configuration=Release
创建发布包,然后:
call myProj.deploy.cmd /Y /M:http://myServer/MSDeployAgentService -allowUntrusted /U:user /:Password
所以这是有效的,它打包然后将其发送到服务器,并正确配置 IIS,但指向错误的数据库。
我的发布资料如下所示:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>MSDeploy</WebPublishMethod>
<SiteUrlToLaunchAfterPublish />
<MSDeployServiceURL>http://myserver</MSDeployServiceURL>
<DeployIisAppPath>Website</DeployIisAppPath>
<RemoteSitePhysicalPath />
<SkipExtraFilesOnServer>True</SkipExtraFilesOnServer>
<MSDeployPublishMethod>RemoteAgent</MSDeployPublishMethod>
<UserName>user</UserName>
<_SavePWD>True</_SavePWD>
<PublishDatabaseSettings>
<Objects xmlns="">
<ObjectGroup Name="DBContext" Order="1" Enabled="False">
<Destination Path="Data Source=server;Initial Catalog=ProductionDB;User ID=user;Password="password"" Name="" />
<Object Type="DbCodeFirst">
<Source Path="DBMigration" DbContext="myproj.Repositories.DBContext, myproj.Repositories" MigrationConfiguration="myproj.Repositories.Migrations.Configuration, myproj.Repositories" Origin="Configuration" />
</Object>
</ObjectGroup>
<ObjectGroup Name="DefaultConnection" Order="2" Enabled="False">
<Destination Path="Data Source=server;Initial Catalog=ProductionDB;User ID=user;Password="password"" Name="" />
<Object Type="DbDacFx">
<PreSource Path="Data Source=localhost;Initial Catalog=devDB;User ID=user;Password="password"" includeData="False" />
<Source Path="$(IntermediateOutputPath)AutoScripts\DefaultConnection_IncrementalSchemaOnly.dacpac" dacpacAction="Deploy" />
</Object>
<UpdateFrom Type="Web.Config">
<Source MatchValue="Data Source=localhost;Initial Catalog=devDB;User Id=user;Password=password" MatchAttributes="$(UpdateFromConnectionStringAttributes)" />
</UpdateFrom>
</ObjectGroup>
</Objects>
</PublishDatabaseSettings>
</PropertyGroup>
<ItemGroup>
<MSDeployParameterValue Include="$(DeployParameterPrefix)DBContext-Web.config Connection String">
<ParameterValue> Data Source=server;Initial Catalog=ProductionDB;User ID=user;Password="password"</ParameterValue>
</MSDeployParameterValue>
<MSDeployParameterValue Include="$(DeployParameterPrefix)DefaultConnection-Web.config Connection String">
<ParameterValue>Data Source=server;Initial Catalog=ProductionDB;User ID=user;Password="password"</ParameterValue>
</MSDeployParameterValue>
</ItemGroup>
</Project>
令人讨厌的是,当直接从 VS2012 发布时,这工作正常,而不是通过命令行。我的 msbuild 调用中是否缺少开关或选项?
在我的 myProj.SetParameters.xml 文件中无法正常工作,其中显示的连接字符串错误。如果我手动将这些更改为正确的连接字符串,则 web.xml 文件在部署后在生产服务器上是正确的。如何将正确的字符串放入我的 SetParameters 文件?任何帮助将不胜感激。
【问题讨论】:
-
你确定你的第一个命令是生成一个包吗?您的发布配置文件的 WebPublishMethod 为
MSDeploy,而不是Package。 -
它正在生成包。您可以使用 MSDeploy 或我正在使用的方法进行部署
-
替代方案,您可以使用 web.config 转换来替换连接字符串,并在执行 MSBuild 时选择要发布的配置。
-
@Thewads - 这对我来说似乎很奇怪。仅当
CreatePackageOnPublish为true或部署到具有WebPublishMethod或Package的发布配置文件时,才应生成包。您确定没有设置其他属性吗? -
@RichardSzalay 我只是按照上面详述的方式运行命令。如果我取出
DeployOnBuild=true则不会构建包
标签: msbuild web-deployment publishing msdeploy webdeploy