Team Services Build Artifacts - msbuild

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.

Related

MSBuild arguments to generate files

notes:
Visual Studio 2017 solution with an MVC web app and several other projects, not all of which are referenced by the web app project. Until now Ive been using VS directly to publish to a test server, but I have moved things into VSTS and have a build & release definition setup but not working yet.
What im trying to achieve, is to get my (hosted) VSTS build agent to produce the published files that my (on-prem) release agent can simply copy to its target destination. So, Im trying to test the MS build step locally from the VS command line so as to get the files produced and note the path they are at. Maybe Im making this more complicated that it needs to be?
These options will create a single zipped archive and its associated files and place it into the artefact staging dir. Is there a way to simply publish the files WITHOUT putting them in an archive - and directly into the artefact staging dir?
Visual Studio Build
MSBuild parameters
/t:My_MVCWeb_Project_Name /p:DeployOnBuild=true
/p:WebPublishMethod=FileSystem /p:PackageAsSingleFile=true
/p:SkipInvalidConfigurations=true
/p:PackageLocation="$(build.artifactstagingdirectory)\\"
In my release using on-prem agent),
I have a "copy files" task, with the destination as the unc path where the IIS app is located. However, that will just copy over the archive. So how can I just copy the files as if I was using a publish profile, straight to the app directory?
[update2 - still getting zip file produced ]
MSBuild my_solution_name /t:"my_project_name" /p:DeployOnBuild=true /p:WebPublishMethod=FileSystem /p:SkipInvalidConfigurations=true /p:PackageLocation="D:\temp\local-dev-build-dir"
[ update 3 ]
Trying these from the command line as a test, but nothing is generated
msbuild D:\app_dir>MSBuild my_solution_name.sln /t:"my_web_proj_name" /p:SkipInvalidConfigurations=true /p:DeployOnBuild=true /p:WebPublishMethod=FileSystem /p:publishUrl="D:\temp\app_build_dir\\"
/p:DeployDefaultTarget=WebPublish
Using these MSBuild Arguments instead:
/p:SkipInvalidConfigurations=true /p:DeployOnBuild=true /p:WebPublishMethod=FileSystem /p:publishUrl="$(build.artifactstagingdirectory)\\" /p:DeployDefaultTarget=WebPublish
Remove the
/p:PackageAsSingleFile=true
Or change it to:
/p:PackageAsSingleFile=false
That is causing the files to be zipped up.
You may also need to switch the publishing method to package:
/p:OutDir=$(build.artifactstagingdirectory)
/p:WebPublishMethod=Package

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 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.

What decides the output files in MSBuild?

From a CI-CD prospective, i am trying to find what are the folder & files (bin, obj, .dll etc) that are published to an IIS server while using the msbuild.exe with the publish option. I am not a .NET developer. What governs which files/folders to be pushed to the nodes while publishing after the build?
My application is a fairly simple one. The publish (or the deployment) is more or less a bunch of file copies from the CI server to the IIS nodes. The command used for the build and publish is
bat '"C:\\MSBuild\\12.0\\Bin\\MSBuild.exe" /p:Configuration=DEV /t:Rebuild /p:DeployOnBuild=true /p:PublishProfile=DEV /m:4 src/myapp.sln'
I am trying to create & place the required output folder & files to an file repository after the msbuild process (before publishing). Then i will use these files to subsequent environments (with their web config files). Thus avoid the rebuilding for each environments.
In this context MSBuild is actually using WebDeploy under the covers to deploy the application. Basically MSBuild compiles any C# OR VB files in the web application project and creates DLLs in the bin directory, then WebDeploy packages up any web server files (HTML/CSS/JS/etc) and the bin folder to the target.
The following post describes how WebDeploy works.
https://dotnetcatch.com/2016/02/25/the-anatomy-of-a-webdeploy-package/

How to include a custom binary file in the published approot in .NET Core DNX?

I'm developing an ASP.NET Core 1.0 application which I deploy to a Linux machine using Docker.
In my CI pipeline I'm publishing the project using dnu publish, then I build the docker image with docker build.
I have a static binary file that I need to use in my docker image. (It's a hotfix which I need to copy into the coreclr runtime directory.) I want to be able to access that file with a command from my Dockerfile.
What is the idiomatic, reliable way to make that file get copied into the output directory when I'm doing dnu publish? What I'm currently doing - because I couldn't find a better solution - is adding it to wwwroot, so it gets copied into wwwroot in the output folder.
However, I don't want that file to be publicly accessible, it would be much better to make it end up in approot.
The approaches I found on SO and tried, but are not working:
Including the file in the project.json as "contentFiles": [ "mylib.so" ]. If I do this, I get the following error during the dnx build:
Error: The process cannot access the file 'C:\myapp\src\myapp.web\mylib.so' because it is being used by another process.
I tried to experiment with creating a custom postBuild script (found the suggestion here: New .NET "project.json" project, copying pre-built native .dlls to the output directory), but I can't figure out where to copy the file, since I have different CI pipelines publishing the same project using different publish output directories, so I cannot hardcode the directory path into my project.json.
Or is there a way to copy it into the build directory, which will be picked up by dnu publish regardless of the output directory of publish?