MSBuild Web Deploy不更新连接字符串

前端之家收集整理的这篇文章主要介绍了MSBuild Web Deploy不更新连接字符串前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我目前正在尝试在生产服务器上启动并运行部署过程.目前我正在使用Web部署和发布配置文件来实现这一点,除了更新连接字符串以适应生产服务器之外,我还能正常工作.

我在用:

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=&quot;password&quot;" 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=&quot;password&quot;" Name="" />
          <Object Type="DbDacFx">
            <PreSource Path="Data Source=localhost;Initial Catalog=devDB;User ID=user;Password=&quot;password&quot;" 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文件获取正确的字符串?任何帮助将不胜感激.

解决方法

最后,为了解决这个问题,在Visual Studio中,我在项目的根目录中创建了一个Parameters.xml文件,该文件包含要在生产服务器上使用的连接字符串的值.拾取并使用它们而不是默认值.

Parameters.xml文件如下所示:

<?xml version="1.0" encoding="utf-8" ?>
<parameters>
    <parameter name="DefaultConnection-Web.config Connection String"
        description=""
        defaultValue=""tags="" />

只需添加您需要的任意数量,并根据需要显然填充属性

猜你在找的HTML相关文章