Web Deployment Tool (MS Deploy)
How can I set parameters for Web Application Project package deployme...
Last post Jun 08, 2010 04:25 AM by ming chen
May 10, 2010 10:06 AM|mkosieradzki|LINK
I have been redirected to this forum from MSBuild forum:
I am trying to configure automatic deployment in MSBuild for my web application project in VS 2010.
Deployment package is created correctly and I managed to autodeploy it to IIS. I need to find way to set up in MSBuild connection string and WebApplication name. Package is autoparametrized correctly but I have trouble setting values for those autoparameters.
I have spent some time reading Microsoft.Web.Publishing.targets and Microsoft.WebApplication.targets. I have found two item group types looking quite promising: MsDeploySimpleSetParameters and MsDeploySetParameters, but they seem to be not referenced anywhere
I tried to do following:
<MsDeploySimpleSetParameters Include="DatabaseConnectionString-Web.config Connection String">
But as I was afraid it is not working - I am probably doing something wrong.
MsDeploy seems to be valid prefix as nearly all public parameters starts with MsDeploy...
I have a workaround for my issue using Web.config transform... but it's not perfect as I would like to configure my connection string based on some msbuild params like AgentId and so on.
Fortunatelly WebApplication path can be set using DeployIisAppPath - so actually only connection string is a problem here.
May 10, 2010 05:41 PM|xinqiu|LINK
To generate a package with the dynamic created parameter, you can try following:
Msbuild test1.csproj /target:package /p: ProjectParametersXMLFile=c:\temp\myParameters.xml
For Parameters.xml definition, please referene
If you'd like to deploy the package with dynamic parameters, you can just use web deploy commandline to do it straightly, reference
Hope it helps
May 10, 2010 06:03 PM|Ming Chen|LINK
In VS. There are several way to do this depending on how do you deploy.
If you are deploy using the batch file (MyApp.Deploy.cmd), you can simply supply your YourApp.SetParameters.xml file right next to the package file. If you look into the batch file, you can provide a environment Variable %_DeploySetParametersFile%. Currently
default to YourApp.SetParameters.xml. (Which leave the default unchange.)
If you have your own deploy script AND would like to change the "DefaultValue" for these parameters. Like you discover, one way is to do the web.config transformation. Auto-ConnectionString will honor web.config transformation's result and pick up as default
value. This is prefered because if customer is VS configuration driven.
Alternatively, you can drop a parameters.xml file. For example, Copy out from zip file and drop it on the root of the project folder. You only need to keep the content you want to change. For example, We will later "marry" the parameter together base
<parameter name="ApplicationServices-Web.config Connection String" description="ApplicationServices Connection String used in web.config by the application to access the database." defaultValue="My test Value1 " tags="SqlConnectionString">
We will later "marry" the parameter together base on priority -- in this case, user parameters file priority is base on $(UserParametersFileParametersPriority) which is -50. The lower number it is, the higher in the priority in getting the value.
Sounds like you want to have Parameters that's base on MSbuild syntax. We have solution for that too. Search for the $(VsWebConfigAutoCsParametersPriority) in The Microsoft.Web.Publising.Targets.
And take the above example, create a WebApplication8.wpp.targets file in your project root folder. (This file will be imported by the Microsoft.Web.Publishing.targets file. WPP stand for web publish pipeline.) Or simply put that in your project file before
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- -50 coming from $(UserParametersFileParametersPriority)
But since this file is before MS.Web.Publishing.targets import, this value is not defined yet. -->
<MsDeployDeclareParameters Include="ApplicationServices-Web.config Connection String">
<DefaultValue>My Test Value</DefaultValue>
<Value>My Test Value</Value>
To make the effect stick, you need to do the following.
1. Close the solution and reopen the solution (VS cache any targets file, Close solution and reload make the targets file updated.)
2. Build->Clean your project (MSDeploy doesn't recongize the parameters chagne as a important breakage for rebuild the packae.)
After that, your project should work like expacted. (We don't expecting user chagne targets file very often.)
Let us know if these solution work for you.
May 10, 2010 06:14 PM|mkosieradzki|LINK
Thank you very much xinqiu and Ming Chen both solutions seems to be perfectly what i needed! I will try to implement one of them starting with with MSDeployDeclareParameters as this is probably the nearest of my wild guess with MSDeploySimpleSetParameters!
May 10, 2010 08:38 PM|mkosieradzki|LINK
MSDeployDeclareParameters works perfectly! Great undocumented feature! I knew it was there! :) Thanks once again ;).
Jun 08, 2010 02:35 AM|Soop|LINK
Does the setting of the %_DeploySetParametersFile% environment variable work correctly?
I am setting it up pointing to my own SetParameters file external to the generated one, but the .cmd file still uses the generated SetParameters file in the deployed directory.
Looking at the .cmd file
if not exist "%_DeploySetParametersFile%" (
echo. "%MSDeployPath%\msdeploy.exe" -source:package='%RootPath%deploy.zip' -dest:%_Destination% -verb:sync -disableLink:AppPoolExtension -disableLink:ContentExtension -disableLink:CertificateExtension %_MsDeployAdditionalFlags%
"%MSDeployPath%\msdeploy.exe" -source:package='%RootPath%deploy.zip' -dest:%_Destination% -verb:sync -disableLink:AppPoolExtension -disableLink:ContentExtension -disableLink:CertificateExtension %_MsDeployAdditionalFlags%
) else (
echo. "%MSDeployPath%\msdeploy.exe" -source:package='%RootPath%deploy.zip' -dest:%_Destination% -verb:sync -disableLink:AppPoolExtension -disableLink:ContentExtension -disableLink:CertificateExtension -setParamFile:"%RootPath%deploy.SetParameters.xml" %_MsDeployAdditionalFlags%
"%MSDeployPath%\msdeploy.exe" -source:package='%RootPath%deploy.zip' -dest:%_Destination% -verb:sync -disableLink:AppPoolExtension -disableLink:ContentExtension -disableLink:CertificateExtension -setParamFile:"%RootPath%deploy.SetParameters.xml" %_MsDeployAdditionalFlags%
That if statement seems to jump into the else block (the %_DeploySetParametersFile% exists) meaning it sets -setParamFile with the generated parameters file ("%RootPath%deploy.SetParameters.xml") not the (%_DeploySetParametersFile%) or is my logic off?
Jun 08, 2010 03:02 AM|Soop|LINK
I think there is a bug with that functionality.. i fixed it by
SET _MsDeployAdditionalFlags="-setParmFile=<path of manual input file>"
That way the .cmd file will use the -setParamFile:"%RootPath%deploy.SetParameters.xml" but then also call -setParamFile:"<path of manual input file>" overwriting the previous value.
Jun 08, 2010 04:25 AM|Ming Chen|LINK
Yes, that's definitly the bug. Please open a bug again VS.