MSBuild Web部署未更新连接字符串
我目前正在尝试在生产服务器上启动并运行部署过程。目前我正在使用WebDeployandPublish配置文件来实现这一点,除了更新连接字符串以适应生产服务器之外,我的一切都正常工作 我正在使用:MSBuild Web部署未更新连接字符串,msbuild,web-deployment,publishing,msdeploy,webdeploy,Msbuild,Web Deployment,Publishing,Msdeploy,Webdeploy,我目前正在尝试在生产服务器上启动并运行部署过程。目前我正在使用WebDeployandPublish配置文件来实现这一点,除了更新连接字符串以适应生产服务器之外,我的一切都正常工作 我正在使用: msbuild myProj.csproj /p:DeployOnBuild=true;PublishProfile=myProfile;Configuration=Release 要创建发布包,请执行以下操作: call myProj.deploy.cmd /Y /M:http://myServer
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>
MSDeploy
http://myserver
网站
真的
远程代理
用户
真的
数据源=服务器;初始目录=ProductionDB;用户ID=用户;Password=“Password”
数据源=服务器;初始目录=ProductionDB;用户ID=用户;Password=“Password”
令人恼火的是,当直接从VS2012发布时,这可以很好地工作,而不是通过命令行。msbuild调用中是否缺少开关或选项
它无法正常工作,因为在myProj.SetParameters.xml文件中,其中显示的连接字符串是错误的。如果我手动将这些更改为正确的连接字符串,那么一旦部署,生产服务器上的web.xml文件就是正确的。如何将正确的字符串放入SetParameters文件?任何帮助都将不胜感激。最后,为了解决这个问题,我在Visual Studio中在项目根目录中创建了一个Parameters.xml文件,其中保存了要在生产服务器上使用的连接字符串的值。将拾取并使用这些值,而不是默认值 Parameters.xml文件如下所示:
<?xml version="1.0" encoding="utf-8" ?>
<parameters>
<parameter name="DefaultConnection-Web.config Connection String"
description=""
defaultValue=""tags="" />
只需添加所需数量,并根据需要填充属性我的DefaultConnection也没有更新。结果我不得不删除MyProject>PublishProfiles.pubxml文件 然后,当尝试发布新构建的项目时,它要求我连接到azure并下载发布配置文件 即使该向导有一个复选框,该复选框可以关闭使用发布配置文件下拉的字符串覆盖DefaultConnection字符串,但取消选中该复选框没有任何效果。它继续覆盖字符串 因此,在azure控制面板(门户)中,我单击了网站>我的网站>配置 向下滚动到连接字符串,可以显示隐藏的连接字符串。我只是通过点击x删除了它,然后在我的web配置中硬编码了正确的一个
然后,我再次删除了.pubxml并再次执行了向导。现在,没有连接字符串与发布配置文件一起下拉。我的发布配置文件。pubxml文件(在Project\Properties\PublishProfiles中找到)已被额外重复的“DefaultConnection-Web.config连接字符串”节点损坏。删除额外节点后,连接字符串已正确更新。您确定第一个命令正在生成包吗?您的发布配置文件的WebPublishMethod是
MSDeploy
,而不是Package
。它正在生成包。您可以使用MSDeploy进行部署,也可以使用我正在使用的方法。或者,您可以使用web.config转换来替换连接字符串,并在执行MSBuild时选择要发布的配置。@Thewads-我觉得很奇怪。仅当CreatePackageOnPublish
为true
或使用Package
的WebPublishMethod
部署到发布配置文件时,才应生成包。你确定没有设置其他属性吗?@RichardSzalay我只是按照上面的详细说明运行命令。如果我取出DeployOnBuild=true
,则不会生成包