Run PreSync/PostSync commands via WPP deploy.cmd - visual-studio-2012

I'm trying to figure out how to run a pre/post command using the deploy.cmd generated by VS/MSBuild. I understand there are pre/postsync commands which can be set on the command line with msbuild but this is fixed within the web deploy package inside of the x.deploy.cmd.
How do I go about customizing the output of this file so that I can run the deploy command with specific parameters?
The intention is a non-developer will pick up the package zip file and import the application into IIS. We use IIS to host some windows services and so to be able to deploy we need to stop and uninstall the service before deployment and then install restart in the post deploy stage.
For certain servers we allow auto deployments from TFS and hook this pre/post command using the .targets file of the msbuild WPP pipeline. However, we want to this to be available to the manual deploy command files.

PreSync/PostSync are features of the msdeploy command line and are not supported by the package/manifest providers, or even the API. They are equivalent to running msdeploy a second time, so there's no way you'll be able to include their functionality while directly importing the package into IIS.
I'd recommend having a batch/powershell file on the server that the user runs after copying the package into the same directory.

The .cmd file that MSBuild generates is boilerplate script that you can simply change to call your pre/post powershell scripts. Just overwrite the one generated by the build with your custom one.

Related

Automate build SQL database projects through VS-CMD, other options?

I'm trying to automate build process for SSDT SQL Database Project.
I have a build script that i can run on VS command prompt to get dacpac file however my window agent doesn't have VS command prompt so i'm looking for other options here.
Please help.
use "Visual studio build" task which will automatically generate dacpac file for you for your database project.
If you pass the solution path to VS build task, it will take all the deployable project inside the solution and creates the necessary artifacts in a separate zip for each deployable project in a solution.
Reference: https://www.gatevnotes.com/continuous-integration-continuous-deployment-of-ssdt-projects-creating-azure-devops-pipelines/
You could use Command Line task to run a program from the command prompt. Azure Pipelines puts your inline script contents into a temporary batch file (.cmd) in order to run it. When you want to run a batch file from another batch file in Windows CMD, you must use the call command:
https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/command-line?view=azure-devops&tabs=classic#running-batch-and-cmd-files
For example :
echo call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Tools\VsDevCmd.bat"

EOL Handling for Windows Pipelines

I have windows apps with XML text files that I edit on windows and check into GitHub. The files have correct Windows EOL formatting on my dev machine. Then I feed it through a Concourse CI pipeline using the Git resource and a windows worker to build an MSI. When I install the MSI on a Windows machine the XML text files have Linux EOL formatting.
What is the best way to fix this? If I understand Concourse correctly the Git resource is a docker container running on Linux so I can see why the files would get checked with Unix EOL formatting but I don't understand why it doesn't get converted to Windows formatting when the container is made available to the windows task.
Update: Slightly more complicated I have some steps that run on the Linux worker so the files need to have Linux EOL formatting when being used on the Linux worker. Example... pull a repos and pass it off to a job running on Linux to do a bunch of npm | grunt | bower type stuff then shuttle the files over to a Windows worker to build some ASP.NET Web API projects and use the Linux output as the Web UI and package it all up into an MSI.
One better way to ensure eol keep consistent is to manage them through .gitattributes core.eol rules
That will avoid the effect of global configurations (applying to all repos) like
git config core.autocrlf
If true, that global rule (possibly active on ConcourseCI) would change eol automatically.
But a .gitattribute can be added to your repo, and will have precedence. That will ensure consistency.

Azure Web Apps - how to run script before deployment

I'm trying to use Azure Web Apps (Linux) to host a basic static site. I configured everything so a new deployment happens with every Git push. I put my pre-built pages in my repo to confirm everything works fine with this setup.
Now I've removed the pre-built pages and kept only the templates and the build script (which is basically just an npm install and a mustatic 'compile') and I'd like to run this build script in my web app. I've scoured the internet but can't find anything.
How can I run a script upon first deployment and after each Git-push-triggered deployment?
How can I run a script upon first deployment and after each Git-push-triggered deployment?
First, you need to generate custom deployment script by using azure-cli tool.
1) Set the cli working mode to asm.
azure config mode asm
2) Run the custom deployment script generator command.
azure site deploymentscript --node -t bash
This will generate the files required to deploy your site.
.deployment - Contains the command to run for deploying your site.
deploy.sh - Contains the deployment script.
Now you can edit the deploy.cmd file and add your custom steps.
After that done, add the generated files to your repository (.deployment and deploy.sh) and push your repository to your Azure Web App and see your custom deployment running.
For more details, please refer to this blog post.

How to auto-generate deploy.cmd in new Azure CLI?

I'm following this guide to create a web app with a custom deploy.cmd file. The article suggests that I can get a copy of the current deploy.cmd file (which I'll then modify) using the following command:
azure site deploymentscript --python
Unfortunately, when I install the Azure CLI using the MSI linked in the article, there is no azure binary on my path. I do have az -- is this a newer version of the same CLI? -- but I can't find an equivalent deployment script generation command for that executable.
I found a deploy.cmd file using Kudu (under D:\home\site\deployments\tools) but am not sure if that's the appropriate file to use. Can anyone suggest the right Azure CLI command for deployment script generation, or confirm that the deploy.cmd file I found is the right one to modify? Thanks in advance!
Based on my knowledge, there is not an equivalent to azure site deploymentscript in azure cli(2.0). So, you could not do deploy custom script with Azure CLI 2.0.
You had better know the difference between Azure cli 2.0(az) with Azure cli 1.0(azure).
Azure CLI 2.0: Our next-generation CLI written in Python, for use with
the Resource Manager deployment model.
Azure CLI 1.0: Our CLI written in Node.js, for use with both the
classic and Resource Managerdeployment models.
For your scenario, if you could install Azure ClI 1.0, you could refer to this link to install Azure CLI 1.0.
Instead of using the command line to generate a starter deployment script, there is an alternative approach that is often easier:
Deploy your repo without any deployment scripts.
Go to the site's Kudu Console.
From the Tools menu, choose 'Download deployment script'. You'll get a zip with a .deployment and deploy.cmd files.
Commit both files at the root of your repo
Tweak them as needed
More information please refer to this link.
You can use kuduscript to generate the deployment script.
npm install -g kuduscript
kuduscript --python
Here is the list of options
Options:
-h, --help output usage information
-V, --version output the version number
-r, --repositoryRoot [dir path] The root path for the repository (default: .)
--aspWAP <projectFilePath> Create a deployment script for .NET web application, specify the project file path
--aspNetCore <projectFilePath> Create a deployment script for ASP.NET Core web application, specify the project file path
--aspWebSite Create a deployment script for basic website
--go Create a deployment script for Go website
--node Create a deployment script for node.js website
--ruby Create a deployment script for ruby website
--php Create a deployment script for php website
--python Create a deployment script for python website
--functionApp [projectFilePath] Create a deployment script for function App, specify the project file path if using msbuild
--basic Create a deployment script for any other website
--dotNetConsole <projectFilePath> Create a deployment script for .NET console application, specify the project file path
-s, --solutionFile <file path> The solution file path (sln)
-p, --sitePath <directory path> The path to the site being deployed (default: same as repositoryRoot)
-t, --scriptType <batch|bash|posh> The script output type (default: batch)
-o, --outputPath <output path> The path to output generated script (default: same as repository root)
-y, --suppressPrompt Suppresses prompting to confirm you want to overwrite an existing destination file.
--no-dot-deployment Do not generate the .deployment file.
--no-solution Do not require a solution file path (only for --aspWAP otherwise ignored).

Jenkins build Visual Studio Solution with Different Configuration

Hi I have a visual studio solution which has been configured in Jenkins. And it's building successfully in debug configuration. How ever I need to change the build configuration to Release or another different one.
So How can I configure Jenkins to select the configuration to build?
If you are using the MSBuild plugin, try adding the configuration flag on the "Command Line Arguments" section:
/p:Configuration=Release
If you are simply building from command line script (batch, powershell, etc), add the above flag there..
What I do, is create a generic job for build process which receives a parameter called "BUILD_CONFIGURATION" from the parent job which triggers it.
And I then reference it in the flag as a variable:
/p:Configuration=${BUILD_CONFIGURATION}

Resources