msdeploy not running dbDacFx provider - msbuild

I am trying to embed my dacpac file in the package and run the dbDacFx provider at deploy time.
using following
visual studio 2010 with Azure publihsing tools and SSDT
SQl Server 2008 R2 with
wpp.targets file in my project.
The file looks like this ...
<AfterAddIisAndContentDeclareParametersItems>
$(AfterAddIisAndContentDeclareParametersItems);
AddAdditionalAclsDeclareParameterItems;
DeployUIConfigDatabase;
</AfterAddIisAndContentDeclareParametersItems>
<Target Name="DeployUIConfigDatabase">
<ItemGroup>
<MsDeploySourceManifest Include="dbDacFx">
<Description>Add dbDacFx $(_MSDeployDirPath_FullPath)\Database\%(CopyAdditionalFilesToDeploy.Identity) to Folder</Description>
<Path>$(_MSDeployDirPath_FullPath)\Database\%(CopyAdditionalFilesToDeploy.Identity)</Path>
<Dest>{UIConfigContext-Web.config Connection String</Dest>
<IncludeTransactionalScripts>True</IncludeTransactionalScripts>
<IncludeData>True</IncludeData>
<AdditionalProviderSettings>IncludeData;IncludeTransactionalScripts</AdditionalProviderSettings>
</MsDeploySourceManifest>
</ItemGroup>
</Target>
i can see that the .zip package has the dacpac file, but when i deploy it, the provider never gets invoked...
Many thanks!

for anyone facing similar issue, looks like you also have to declare a parameter that gets used by msdeploy during deployment phase. Adding following to my wpp file produced the right parameter file and everything works now.
<Target Name="AddAdditionalDeployUIConfigDatabase">
<ItemGroup Condition="'#(CopyAdditionalFilesToDeploy)' != ''">
<MsDeployDeclareParameters Include="Add dbDacFx Provider Parameter %(CopyAdditionalFilesToDeploy.Identity)">
<Kind>ProviderPath</Kind>
<Scope>dbDacFx</Scope>
<Description>Run dbDacFx provider on %(CopyAdditionalFilesToDeploy.Identity)</Description>
<DefaultValue>{UIConfigContext-Web.config Connection String}</DefaultValue>
<DestinationContentPath>$(_MsDeployParameterNameForContentPath)/#(CopyAdditionalFilesToDeploy)</DestinationContentPath>
<Tags>Hidden</Tags>
<ExcludeFromSetParameter>True</ExcludeFromSetParameter>
</MsDeployDeclareParameters>
</ItemGroup>

Related

Error of 'Source (dirPath) and destination (iisApp) are not compatible for the given operation' when trying to deploy package

I'm trying to deploy a package via the MSDeploy task from within MSBuild.
I have configured two Item Groups to represent my source and destination.
The source is a package I have created eg. Solution.zip
The destination is IIS 7 on a remote server.
The configuration looks like this :
<ItemGroup>
<DeploySource Include="package">
<Path>$(PackagePath)</Path>
</DeploySource>
</ItemGroup>
<ItemGroup>
<DeployDestination Include="iisApp">
<ComputerName>https://myserver.com/msdeploy.axd</ComputerName>
<UserName>XXXXXXXX</UserName>
<Password>XXXXXXXX</Password>
<AuthType>Basic</AuthType>
<Path>Default Web Site/Umbraco.Web_deploy</Path>
</DeployDestination>
</ItemGroup>
<PropertyGroup>
<ConfigFileName>Staging.config</ConfigFileName>
</PropertyGroup>
I then call the MSDeploy task within MSBuild like this :
<Target Name="Deploy_v2">
<!-- Using ContinueOnError due to a bug in MSDeploy task-->
<MSDeploy
ContinueOnError="true"
ToolPath="C:\Program Files\IIS\Microsoft Web Deploy V3"
Verb="sync"
Source="#(DeploySource)"
Destination="#(DeployDestination)"
AllowUntrusted="true"
Replace="objectName=filepath,match=Configs\$(ConfigFileName),replace=web.config"
/>
</Target>
This results in the following command line execution
C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe -source:package='C:\CLIENTS\DAM\Components\Umbraco\SiteTemplate_v6_1_6\Output\Package\UmbracoTemplate_v6_1_6.zip' -dest:iisApp='Default WebSite/Umbraco.Web_deploy',ComputerName='https://myserver.com/msdeploy.axd',UserName='XXXXXXX',Password='XXXXXXXX',AuthType='Basic' -verb:sync -replace:objectName=filepath,match=Configs\Staging.config,replace=web.config -allowUntrusted
Which unfortunately results in the following error :
MSDEPLOY : Error: Source (dirPath) and destination (iisApp) are not compatible for the given operation.
It seems to me that MSDeploy is viewing my package as a dirPath. When I created the package it did use a dirPath as its source.
As the error states dirPath and iisApp are not compatible providers, although iisApp does use dirPath. See here
iisApp can take a directory as the source so try packaging the target directory via iisApp as follows:
msdeploy -verb:sync -source:iisApp=c:\inetpub\wwwroot -dest:package=Package.zip
Btw if you are using Visual Studio you can generate an MSDeploy package using MSBuild with /t:Publish.

Modify files after deployment package is created

I'm in the process of creating a web deployment package through an automatic build trigger on the server.
The package should take care of everything (including creation of a specific website, apppool, and the latest code) on any server desired.
I extracted manually a deploy package from a configured local IIS site, containing all information needed by MsDeploy to create the site, apppool, etc...
They are present in following files
archive.xml
parameters.xml
systeminfo.xml
The idea is now that I would create automatic a deploy package on the build server, that contains the new compiled code, but with the above xml files in the .zip package.
Right now, I'm building the application, after which I execute a PowerShell script that will manually overwrite the files in the .zip with the ones I have.
However, I know you can extend the Target file (with a .wpp.targets file in your project) to plug into the pipeline and modify things along the way.
Unfortunately I'm getting a little lost with the information I found.
I'd like to:
1) configure the creation of the deployment package to use my existing .xml files.
2) if that's not possible, overwrite the files with my own files after the package creation.
My goal is to have a full executable deploy package after the build is finished, so I won't need to PowerShell script anymore.
Any information that will point me closer to a solution or helps me to understand more clearly msbuild targets and/or webdeploy is very appreciated.
I managed doing this by extending the Package MsBuild target.
Adding a .wpp.targets file in the root of the web project with following content.
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\MSBuild.ExtensionPack.4.0\MSBuild.ExtensionPack.tasks"/>
<PropertyGroup>
<DeployFilesDirectory>$(MSBuildProjectDirectory)\Deploy\</DeployFilesDirectory>
</PropertyGroup>
<PropertyGroup>
<OnAfterPackageUsingManifest>
$(OnAfterPackageUsingManifest);
CopyDeployFiles;
ReplaceSetParametersFile;
<!--ZipDeploymentFiles;-->
</OnAfterPackageUsingManifest>
</PropertyGroup>
<Target Name="CopyDeployFiles">
<Message Text="Copy Deploy Files"></Message>
<ItemGroup>
<Files Include="$(DeployFilesDirectory)*.xml" Exclude="$(DeployFilesDirectory)setParameters.xml"></Files>
</ItemGroup>
<MSBuild.ExtensionPack.Compression.Zip TaskAction="AddFiles"
CompressFiles="#(Files)"
ZipFileName="$(PackageFileName)"
RemoveRoot="$(DeployFilesDirectory)"/>
</Target>
<Target Name="ReplaceSetParametersFile" DependsOnTargets="GenerateSampleDeployScript">
<Message Text="Replace Default SetParameters File"></Message>
<Copy DestinationFiles="$(GenerateSampleParametersValueLocationDefault)"
SourceFiles="$(DeployFilesDirectory)setParameters.xml"></Copy>
</Target>
</Project>
The first target is executed after MsDeploy has created the package and will replace the .xml files within the .zip file. I'm using the MsBuild.ExtensionPack Zip support.
The second target is executed after the build has created the sample .cmd and setParameters files and will overwrite the setParameters.xml with my own as well.
It takes a while to understand the concepts of MsBuild targets etc, but once you understand it becomes indeed very powerful.
Creating the package is now as simple as just launching the MsBuild
msbuild "D:\Projects\MyWebProject.csproj" /T:Package /P:Configuration=Release;Platform="AnyCPU";PackageLocation="D:\DeployPackage\package.zip";PublishProfile=MyProfile
And deploying is the same as before
package.deploy.cmd /Y –setParamFile :myParameterFile.xml
Assuming your paths stay the same, you can achieve this by specifying the existing zip as your -dest:package=package.zip. MSDeploy will automatically overwrite the files inside the zip.

how to publish my WCF Service Library using MSBuild Command Line in VS 2012?

I want to Publish my WCF Service Library using MSBuild Command Line with VS2012, i don't want to do right click->Publish Website , instead i want to publish it using Command Prompt(MSBuild).
What are the Pre-requisites required for MSBuild?
I don't have windows azure,it is necessary to install windows azure?
I am new to MSBuild, and I would like step by step instructions on how to accomplish this?
I want the .svc file, all the dll's inside the bin folder and web config file to be present inside the published folder.
I found the answer for my question with the reference as below link,
"http://www.asp.net/mvc/tutorials/deployment/visual-studio-web-deployment/command-line-deployment"
using the command line "msbuild C:\ContosoUniversity\ContosoUniversity.sln /p:DeployOnBuild=true /p:PublishProfile=Test"
Your solution is fine and will work to deploy directly out to your host (don't forget to include your build Configuration so it publishes the correct config transform).
Another option is to "publish" your site to a local folder and then upload it to your host separately. This also gives you a chance to archive the site in a zip, do post checks and troubleshoot.
You can do this like so:
<MSBuild Projects="WebProject.csproj"
Targets="Rebuild;_WPPCopyWebApplication"
Properties="WebProjectOutputDir=WebProject\;UseWPP_CopyWebApplication=True;PipelineDependsOnBuild=False;" />
If you get stuck there are more details on publishing WCF, ASP.NET and MVC projects.
You can try with this.
The svc file was manually generated for first time use and then added to the project.
Content Include="*.svc" ---- Change this with the name of the file generated by VS Publish Option.
<ItemGroup>
<Content Include="*.svc">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<WebConfig Include="App.config" />
</ItemGroup>
<Target Name="AfterBuild">
<Copy SourceFiles="#(WebConfig)" DestinationFiles="$(OutDir)web.config" />
</Target>

MSBuild + .dbproj

i am trying to deploy db project through msbuild.
i am getting below error
MSBuild - Deploy DB project
C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe
/nologo
/noconsolelogger "C:\Builds\2\Test\ePlanner\Sources\WebSiteBuildTest\Database\ePlanner\ePlanner\ePlanner.dbproj"
/m:1
/t:"Deploy"
/fl
/flp:"logfile=deploymentdb.log;encoding=Unicode;verbosity=normal"
/p:TargetDatabase="ePlanner3";"TargetConnectionString="Data Source=SACHIN-PC%3Buser=sa%3Bpwd=M0nday!";"DefaultDataPath="C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA";DeployToDatabase=true
/p:OutDir="C:\Builds\2\Test\ePlanner\Binaries\\"
/p:Configuration="Debug"
/p:RunCodeAnalysis="False"
/dl:WorkflowCentralLogger,"C:\Program Files\Microsoft Team Foundation Server 2010\Tools\Microsoft.TeamFoundation.Build.Server.Logger.dll";"Verbosity=Normal;BuildUri=vstfs:///Build/Build/53;InformationNodeId=10631;TFSUrl=http://sachin-pc:8080/tfs/DefaultCollection;"*WorkflowForwardingLogger,"C:\Program Files\Microsoft Team Foundation Server 2010\Tools\Microsoft.TeamFoundation.Build.Server.Logger.dll";"Verbosity=Normal;"
MSBUILD : error MSB1008: Only one project can be specified.
Switch: Source=SACHIN-PC%3Buser=sa%3Bpwd=M0nday!;
DefaultDataPath=C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA;DeployToDatabase=true
For switch syntax, type "MSBuild /help"
TF270015: 'MSBuild.exe' returned an unexpected exit code. Expected '0'; actual '1'.
Please help me out
In order to run a .dbproj in MsBuild the machine needs to have VisualStudio with the database project components installed, something to do with licensing. I cannot tell from the error dump that you provided if this is what is causing you the issue but it solved our issue when building on our build server.
You've got conflicting quotation marks in your command line:
/p:TargetDatabase="ePlanner3";"TargetConnectionString="Data Source=SACHIN-PC%3Buser=sa%3Bpwd=M0nday!";"DefaultDataPath="C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA";DeployToDatabase=true
The TargetConnectionString property is completely surrounded in double quotes, but then you use double quotes to specify the connection string. Try escaping the quotes for the connection string.
Consider converting the project to .sqlproj. This new format provides a "Publish" MSBuild target. You just need to specify at SqlPublishProfilePath property a publish profile file with your deployment options.
Look that sample:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="ProjectsBuild">
<ItemGroup>
<!-- Defines a collection of projects to deploy -->
<ProjectsToPublish Include="SQLServer.sqlproj">
<Properties>SqlPublishProfilePath=myprofile.publish.xml</Properties>
</ProjectsToPublish>
<!-- Runs the target Publish -->
<MSBuild Projects="#(ProjectsToPublish)" Targets="Publish"/>
</ItemGroup>
</Project>
Visual Studio 2010/2012 needs the SSDT (Sql Server Data Tools - ) installed to understand .sqlproj. Your build server too. It will install the MSBuild .targets extensions that contains the target "Publish".
Publish profile example (it's a MSBuild project):
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<CreateNewDatabase>True</CreateNewDatabase>
<TargetDatabaseName>DB1</TargetDatabaseName>
<TargetConnectionString>Data Source=server1\dev;Integrated Security=True;Pooling=False</TargetConnectionString>
<BackupDatabaseBeforeChanges>False</BackupDatabaseBeforeChanges>
<BlockOnPossibleDataLoss>False</BlockOnPossibleDataLoss>
<NoAlterStatementsToChangeCLRTypes>False</NoAlterStatementsToChangeCLRTypes>
<DropObjectsNotInSource>True</DropObjectsNotInSource>
<DeployDatabaseInSingleUserMode>False</DeployDatabaseInSingleUserMode>
<DeployScriptFileName>db1.sql</DeployScriptFileName>
<ProfileVersionNumber>1</ProfileVersionNumber>
</PropertyGroup>
</Project>

Overriding MSBuildExtensionsPath in the MSBuild task is flaky

This is already cross-posted at MS Connect:
https://connect.microsoft.com/VisualStudio/feedback/details/560451
I am attempting to override the property $(MSBuildExtensionsPath) when building a solution containing a C# web application project via msbuild. I am doing this because a web application csproj file imports the file "$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets". This file is installed by Visual Studio to the standard $(MSBuildExtensionsPath) location (C:\Program Files\MSBuild). I would like to eliminate the dependency on this file being installed on the machine (I would like to keep my build servers as "clean" as possible). In order to do this, I would like to include the Microsoft.WebApplication.targets in source control with my project, and then override $(MSBuildExtensionsPath) so that the csproj will import this included version of Microsoft.WebApplication.targets. This approach allows me to remove the dependency without requiring me to manually modify the web application csproj file.
This scheme works fine when I build my solution file from the command line, supplying the custom value of $(MSBuildExtensionsPath) at the command line to msbuild via the /p flag. However, if I attempt to build the solution using the MSBuild task in a custom msbuild project file (overriding MSBuildExtensionsPath using the "Properties" attribute), it fails because the web app csproj file is attempting to import the Microsoft.WebApplication.targets from the "standard" Microsoft.WebApplication.targets location (C:\Program Files\MSBuild). Notably, if I run msbuild using the "Exec" task in my custom project file, it works. Even more notably, the FIRST time I run the build using the "MSBuild" task AFTER I have run the build using the "EXEC" task (or directly from the command line), the build works.
Has anyone seen behavior like this before? Am I crazy? Is anyone aware of the root cause of this problem, a possible workaround, or whether this is a legitimate bug in MSBuild?
Steps to Reproduce:
1) Create a new empty solution in MSVS 2008 (Fake.sln)
2) Add a new C# web application to the solution (WebApplication1.csproj)
3) Close MSVS
4) Copy the contents of "C:\Program Files\MSBuild\" to a directory called "MSBuildExtensions" in the directory containing your solution.
5) rename the directory "C:\Program Files\MSBuild\Microsoft\VisualStudio\v9.0\WebApplications" so that WebApplication1.csproj will not be able to import Microsoft.WebApplication.targets from that location.
6) Create a custom MSBuild project file called "TestBuild.proj" in the same directory as the solution. It should have the following content:
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="BuildMSBuild">
<PropertyGroup>
<MSBuildExtensionsPath>$(MSBuildProjectDirectory)\MSBuildExtensions\</MSBuildExtensionsPath>
<BuildThis>Fake.sln</BuildThis>
</PropertyGroup>
<Target Name="BuildMSBuild">
<MSBuild Projects="$(BuildThis)" Properties="MSBuildExtensionsPath=$(MSBuildExtensionsPath);" Targets="Clean" />
<MSBuild Projects="$(BuildThis)" Properties="MSBuildExtensionsPath=$(MSBuildExtensionsPath);"/>
</Target>
</Project>
7) execute "msbuild TestBuild.proj" from a MSVS command prompt (note: the build may succeed the first time, but will fail if you run more than once)
Did you try setting the environment variable MSBuildExtensionPath in the CMD prompt and then running your build?
For example:
C:\> SET MSBuildExtensionsPath=C:\My\MSBuild\Extensons
Then on this project file:
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Build">
<Message Text='MSBuildExtensionsPath="$(MSBuildExtensionsPath)"' />
</Target>
</Project>
you will get the following output:
c:\Users\chuckeng\Desktop\ConsoleApplication1>"C:\Windows\Microsoft.NET\Framework\v3.5\MSBuild.exe" my.proj
Microsoft (R) Build Engine Version 3.5.30729.4926
[Microsoft .NET Framework, Version 2.0.50727.4927]
Copyright (C) Microsoft Corporation 2007. All rights reserved.
Build started 6/25/2010 1:04:05 PM.
Project "c:\my.proj" on node 0 (default targets).
MSBuildExtensionsPath="C:\My\MSBuild\Extensons"
Done Building Project "c:\my.proj" (default targets).
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:00.03
This works from v4.0 as well. Although, support is generally better in v4.0 for things like this. And, v4.0 is 100% backward compatible (bugs not withstanding). So, you can build your v3.5 and prior projects with v4.0. Just select ToolsVersion 3.5.
msbuild my.proj /tv:3.5
Hope this helps...
Chuck England
Visual Studio
Program Manager - MSBuild
This is a bug in MSBuild 3.5 but it is fixed in MSBuild 4.
If you can, switch to MSBuild 4 (you still can compile your 3.5 projects), otherwise you'll have to override the property in the project file.
It works fine if you override MSBuildExtensionsPath directly in the web app .csproj file.
<PropertyGroup>
<MSBuildExtensionsPath>C:\Users\madgnome\Desktop\msbuild</MSBuildExtensionsPath>
<!-- It works too with relative path -->
<!--<MSBuildExtensionsPath>..\msbuild</MSBuildExtensionsPath>-->
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
Don't know if this might help anyone in the future, but I was able to use the following at the top of my file and it works as I would expect in both 32 and 64 bit build environments.
<PropertyGroup>
<MSBuildExtensionsPath Condition=" '$(MSBuildExtensionsPath64)' != '' ">$(MSBuildExtensionsPath64)</MSBuildExtensionsPath>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\ExtensionPack\4.0\MSBuild.ExtensionPack.tasks"/>