The*_*ads 5 msbuild publishing web-deployment msdeploy webdeploy
我目前正在尝试在生产服务器上启动并运行部署过程.目前我正在使用Web部署和发布配置文件来实现这一点,除了更新连接字符串以适应生产服务器之外,我还能正常工作.
我在用:
msbuild myProj.csproj /p:DeployOnBuild=true;PublishProfile=myProfile;Configuration=Release
Run Code Online (Sandbox Code Playgroud)
创建发布包,以及:
call myProj.deploy.cmd /Y /M:http://myServer/MSDeployAgentService -allowUntrusted /U:user /:Password
Run Code Online (Sandbox Code Playgroud)
所以这是有效的,它打包然后将其发送到服务器,并正确配置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>
Run Code Online (Sandbox Code Playgroud)
令人讨厌的是,这直接从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="" />
Run Code Online (Sandbox Code Playgroud)
只需添加您需要的数量,并根据需要填充属性即可
归档时间: |
|
查看次数: |
5815 次 |
最近记录: |