Posts tagged .net
Automated Web Deployment with MSBuild and MSDeploy
0If you are looking for an automated web deployment process you will inevitably come to MSBuild.
There are many tutorials out there how to set up a command line call for MSBuild but you wont find a documentation how to publish a generated package with MSDeploy.
But this is especially needed is you want to use “-setParam” for a tokenized (transformed) web.config file and wont / can’t change the SetParameter.xml!
(The names of the parameters for -setParam can be found in the SetParameter.xml file in the same directory as the Package.zip. They are also act as default values if not set in the command line call. )
So I wrote this quick tutorial how to get command line call for MSDeploy.
(Please consider that the paths you will later use are absolute / relative to the working directory.)
Step 1: Get the publish ready with MSBuild
Before we will get some further results please get your deployment call working.
msbuild.exe
SomeWebProject.csproj
/P:Configuration=Release
/P:DeployOnBuild=True
/P:DeployTarget=MSDeployPublish
/P:MsDeployServiceUrl=https://TargetServer/MsDeploy.axd
/P:AllowUntrustedCertificate=True
/P:MSDeployPublishMethod=WMSvc
/P:CreatePackageOnPublish=True
/P:UserName=Username
/P:Password=Password
/P:DeployIisAppPath=TargetWebSite/TargetWebApp
Configuration: This is the configuration you will use eg. Debug, Release or a custom one
AllowUntrustedCertificate: You will need this if you do not have a valid certificate on the server
DeployIisAppPath: The name of the target website eg. “Default Web Site/MyWebApp”
TargetWebSite/TargetWebApp: Please consider the different usages below!
Step 2: Get the command line for MSDeploy
Append the parameter “/P:UseMsdeployExe=True” to the msbuild.exe call. If you do so, you will see the call in the console like this:
MSDeployPublish:
Start Web Deploy Publish the Application/package to https:/TargetServer/MsDeploy.axd?site=TargetWebSite …
Running msdeploy.exe.
msdeploy.exe -source:package=’C:\SomeWebProject\obj\Release\Package\SomeWebProject.zip‘ -dest:auto,ComputerName=’https://TargetServer:8172/MsDeploy.axd?site=TargetWebSite‘,UserName=’Username‘,Password=’Password‘,IncludeAcls=’False’,AuthType=’Basic’ -verb:sync -disableLink:AppPoolExtension -disableLink:ContentExtension -disableLink:CertificateExtension -allowUntrusted -retryAttempts=2
Gotcha! This is the important MSDeploy command line call.
Step 3: Get the two things together
now we can split the automatic deployment of MSBuild into 1. create only the package with MSBuild and 2. only deploy with MSDeploy.
msbuild.exe
SomeWebProject.csproj
/P:Configuration=Release
/P:DeployOnBuild=True
/P:CreatePackageOnPublish=True
msdeploy.exe
-source:package=’C:\SomeWebProject\obj\Release\Package\SomeWebProject.zip‘
-dest:auto,ComputerName=’https://TargetServer:8172/MsDeploy.axd?site=TargetWebSite‘,UserName=’Username‘,Password=’Password‘,IncludeAcls=’False’,AuthType=’Basic’
-verb:sync
-disableLink:AppPoolExtension
-disableLink:ContentExtension
-disableLink:CertificateExtension
-allowUntrusted
-retryAttempts=2
-setParam:’IIS Web Application Name’=’TargetWebSite/TargetWebApp‘
Have a nice day.
Determine ClickOnce UpdateUri / Install Address
0Its hard to find Informations about the place where the UpdateUri is saved on a windows machine.
The only information i was found is where the binaries of a ClickOnce application is stored.
This whould be:
C:\Users\UserName\AppData\Local\Apps\2.0\ (Vista)
C:\Documents and Settings\UserName\Local Settings\Apps\2.0\ (XP)
The UpdateUri of a particular application can be found in the registry:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall\[APP-ID]\UrlUpdateInfo
The key will contain a string like this:
http://somedomain.com/ApplicationName/ApplicationName.application
If this address is called in the browser (InternetExplorer or Firefox with AddOn), the application starts to install.
If you change the ApplicationName.application to publish.htm, a install page will be displayed.
Binding to an anonymous type
0Try to imagine that you have a list of complex classes and you just want to display just a bunch of properties.
For example:
Person.Firstname,
Person.Lastname,
Person.Address.District.Name,
Person.Cars[0].Brand,
Person.Cars[1].Brand
I was playing around with ValueConverter and found out, that i can return an anonymous type out of the converter and bind it to a textblock’s content.
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value is Persons) { var persons = (Persons)value; var query = from person in persons let firstname = person.Firstname let lastname = person.Lastname let districtname = person.Address.District.Name let car1 = person.Cars[0].Brand let car2 = person.Cars[1].Brand select new { Firstname = firstname, Lastname = lastname, Districtname = districtname, Car1 = car1, Car2 = car2 }; return query; } return value; } |
Updating the values as you maybe guess don’t work, but if you dont want to write complex bindings you can use this technique to archive the result.
NeutralResourcesLanguageAttribute is Evil for ResourceFiles
0Imagine this:
Two Resource files named Strings.resx and Strings.de.resx.
The first (neutral) contains english content, the second german content.
If you ask youself over and over again why the f**k the ResourceManager returns the neutral language even you use the specified language “de”, look into your AssemblyInfo.cs file.
If there is a [assembly: NeutralResourcesLanguage("de")], the ResourceManager from this Assembly thinks you want to get the neutral language if you ask for “de” explicit.
This attribute is used to overrule the neutral settings to a specific one.
Deleting this from your AssemblyInfo.cs can help you realy much in this case.
