Skip and include files during deploy - msbuild

I'm using this MSBuild command to deploy my web app.
/P:Configuration=Staging
/P:DeployOnBuild=True
/P:DeployTarget=MSDeployPublish
/P:MsDeployServiceUrl=192.168.1.5:8172/MsDeploy.axd
/P:AllowUntrustedCertificate=True
/P:DeployIisAppPath="Default Web Site/test"
/P:username=Administrator
/P:password=*****
/P:MSDeployPublishMethod=WMSVC
I need to somehow change this configuration to do this:
Exclude some folders from deploy
Deploy a folder which is not part of the project. This folder is created on the build server right before the deploy. It does not exist in the source control.
BTW I'm using Teamcity

You should create a publish profile (via the Publish dialog) that contains all the publish properties, except password, and then execute it via:
/P:Configuration=Staging
/P:DeployOnBuild=True
/P:PublishProfile=Test
/P:Password=*****
Exclude some folders from deploy
Add this to your newly created pubxml as a direct child of the root element:
<ItemGroup>
<MsDeploySkipRules Include="Uploads Folder">
<ObjectName>dirPath</ObjectName>
<AbsolutePath>Uploads$</AbsolutePath> <!-- Regex -->
</MsDeploySkipRules>
</ItemGroup>
Deploy a folder which is not part of the project. This folder is created on the build server right before the deploy. It does not exist in the source control
See this answer

Related

Using VSTS to publish Azure Function to Zip file

I am trying to use VSTS to publish a project that contains an Azure Function. My MSBuild step is passing the following build arguments
/p:Configuration=Release /p:DeployOnBuild=true
/p:WebPublishMethod=Package /p:PackageAsSingleFile=true
/p:SkipInvalidConfigurations=true
/p:PackageLocation="$(build.artifactstagingdirectory)\MyFunctions.$(Build.BuildNumber)-dev.zip"
/p:DeployIisAppPath="Default Web Site"
This is giving me a Zip where the folder structure of \Content\D_C\a\3\s\MyFunctions\obj\Release\net461\PubTmp\Out. The Out directory has the content I need and what I'd expect to be the root
The folder structure I need to push a Zip is
As documented Here
Can anyone advise on what I am doing wrong here?
Thanks
I do it in a 2 step process
build with a VSTS Build task with settings /p:DeployOnBuild=true /p:DeployTarget=Package;CreatePackageOnPublish=true
ZIP it with a VSTS Archive Files task. Here I leave the option to Prefix root folder name... unchecked.
Sample:
With Azure App Service Deploy task and Publish using Web Deploy option, it won’t remain the folder structure and the content files will be in wwwroot folder of azure app service. So you don’t need to care the package folder structure.
Otherwise, you can publish the app through FileSystem publish method (e.g. /p:SkipInvalidConfigurations=true /p:DeployOnBuild=true /p:WebPublishMethod=FileSystem /p:publishUrl="$(build.artifactstagingdirectory)\\" /p:DeployDefaultTarget=WebPublish), then zip files through Archive files task, after that you can deploy it through Zip push deployment way (Azure CLI or PowerShell)
Zip push deployment for Azure Functions

Team Services Build Artifacts

I'm attempting to create a build that will build my solution, apply web.config transforms as necessary and finally copy desired output (a built web api project) to the artifacts area of the build.
I'm using the Deployment...Azure WebApp Template with the Azure App Service Deploy step disabled (as we're in the middle of a move to Azure), with the following build arguments in the build step:
/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\" /p:AutoParameterizationWebConfigConnectionStrings=False
All works as expected, apart from the structure of the resulting zip file, which has the following structure:
{ZipFileName}{ProjectName\Content\C_C\a\1\s\Api{ProjectName\obj\Release\Package\PackageTmp...{BuildContent}
I'd like the content to be at the root of the published zip file if possible. Is the best way to manipulate the content of $(build.artifactstagingdirectory) using Powershell or a number of the other built in build tasks?
You don’t need to worry about it, because it won’t keep the folder structure (Just the files and folders in PackageTmp folder) after deploy to web server (e.g. IIS, Azure Web App)
If you still need to just include the files in PackageTmp folder, you can add build step to archive file to zip file through Archive Files step.
For Visual Studio Build step, specify /p:DeployOnBuild=true to MSBuild Arguments.

Team Services build windows service to the deploy folder

net sln witch has a website project and also a windows service project. Within team services and on my build job I am able to output the website to the drop folder using the following
/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\"
I need to also output the windows service to another folder within the drop folder
Any help would be great
You need to add Copy files task to copy files to artifact directory (Below Publish symbols path task) https://www.visualstudio.com/en-us/docs/build/steps/utility/copy-files.
For example:
The BuildConfiguration variable is in Variables tab, default is release, you may need to change to debug if you build project with debug configuration.

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.

Teamcity delay copying artifacts

I m running MSBuild script to compile my project and iv set a artifact path in the general settings of TeamCity. My MSBuild scripts first build and then creates a zip file. I would like to add that zip file as a artifact but when i run the build on TeamCity i get this error:
[17:44:56]: [CreateNightlyZip] Zip
[17:44:56]: [Zip] C:\BuildAgent\Build\Build.proj(55, 5): The process cannot access the file 'C:\BuildAgent\work\c13cf8f192b25cd1\bin\Debug\20120109_Foo.PE.zip' because it is being used by another process.
So it lookes like TeamCity tries to grab the zip file right when its created and then my MSBuild script fails to put files into it.
Here is the MSBuild target:
<Target Name="CreateNightlyZip">
<PropertyGroup>
<StringDate>$([System.DateTime]::Now.ToString('yyyyMMdd'))</StringDate>
</PropertyGroup>
<ItemGroup>
<DebugApplicationFiles Include="$(DebugPath)\**\*.*" Exclude="$(DebugPath)\*vshost.exe*" />
</ItemGroup>
<MakeDir Directories="$(NightlyBuildPath)"/>
<Zip Files="#(DebugApplicationFiles)"
WorkingDirectory="$(DebugPath)"
ZipFileName="$(NightlyBuildPath)\$(StringDate)_$(NightlyZipName).zip"
ZipLevel="9" />
</Target>
Have anybody had this problem allso or what should be solution for this?
EDIT: What is strange is that when i create zip file in the root of checkout folder then everything works, but when i create it to the Debug folder then i get this error.
TeamCity publishes artifacts only when all build steps are finished, i.e. when MSBuild script finishes.
To publish artifacts during the build you need to produce special service message from the build script when artifacts are ready: http://confluence.jetbrains.net/display/TCD65/Build+Script+Interaction+with+TeamCity#BuildScriptInteractionwithTeamCity-PublishingArtifactswhiletheBuildisStillinProgress
If you do not use service messages, you should check which process locked the file. Maybe you have two agents on the same machine running builds simultaneously and interfering with each other?
What i ended up doing is not to place the created .zip file into the debug folder and just to the project root folder. Doing that the zip file is created and Teamcity is able to use it as artifact.