I was using publish to folder option through Visual Studio by right-clicking on the project -> publish -> publish to folder. Result was always ready-to-copy project with applied transformations.
I wanted to automate this process using VSTS and have setup build on VSTS.
I used next steps:
- NuGet restore
- Build solution
- Publish Build Artifacts to $(build.artifactstagingdirectory)
- Windows machine file copy from $(build.artifactstagingdirectory) to remote machine using admin login and password
And finally I'm getting zip package on remote machine with complicated folder structure without applied transformations inside at all.
What is wrong? How I can setup same "publish to folder" as in Visual Studio but using VSTS?
Add below Target to your .csproj to enable transforming config files
<Target Name="TransformConfigFiles" AfterTargets="AfterBuild" Condition="'$(TransformConfigFiles)'=='true'">
<ItemGroup>
<DeleteAfterBuild Include="$(WebProjectOutputDir)\Web.*.config" />
</ItemGroup>
<TransformXml Source="Web.config" Transform="$(ProjectConfigTransformFileName)" Destination="$(WebProjectOutputDir)\Web.config" />
<Delete Files="#(DeleteAfterBuild)" /></Target>
In your build solution step add the following build arguments "/p:TransformConfigFiles=true" will make the config transformation using the above added target to .csproj
/p:TransformConfigFiles=true /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:OutDir="$(build.stagingDirectory)"
Then you can use a publish step to publish your $(build.stagingDirectory) contents. You can use $(build.stagingDirectory)_PublishedWebsites as path to publish if you only need the website output.
This will allow you to get the ms deploy package as well as xcopy deploy published website files.
You can use copy files task before the publish task to copy any additional files if you have any to $(build.stagingDirectory) and get them published as build artifacts.
Use VSTS release management with deployment groups to deploy your application to target server. You can use IIS deploy task to deploy to IIS using ms deploy package. If you are using web deploy package you can use a parameters.xml in your web app to get the web config parameters assigned to .setparameters.xml so that you can change values in the deployment time using IIS deployment task.
You are publishing web application through File System method, it is based on the specified configuration (e.g. Debug, Release) to transform web.config. So you need to check which configuration you specified in build solution task (e.g. Visual Studio Build task)
Simple tasks:
NuGet Tool Installer task
NuGet restore task
Visual Studio Build task (MSBuild Arguments: /p:SkipInvalidConfigurations=true /p:DeployOnBuild=true /p:WebPublishMethod=FileSystem /p:publishUrl="$(build.artifactstagingdirectory)\\" /p:DeployDefaultTarget=WebPublish; Platform: $(BuildPlatform); Configuration: $(BuildConfiguration)) Note: BuildPlatform and BuildConfiguration are build variables. It will publish web app to artifacts directory ([agent working folder]/1/a)
Publish Build Artifacts (Path to publish: $(build.artifactstagingdirectory))
Related
I created a .netcore 2.1 api project and set up Azure DevOps to deploy it to an On-Prem computer using the Windows Agent.
The folder agent_work\r1\a was created on the machine running the agent, however there are no files in it.
I can see that a build did occur and that there is an artifact in my release
What did I miss doing?
[Update]
I can see in the agent job, there is a section which is about downloading an artifact.
It has the error message
There is no build available or the source is not accessible. You can select all artifacts or specify the list of artifacts to be downloaded below.
[Update]
Looks like I need to add a task to the job that is in a stage of my release.
And that task needs to copy the files I want to deploy.
Now the problem is knowing how to specify the source folder.
The strange thing is that it allows me to select a location and then rejects the selected location
There is help that says that if I leave the source folder empty, that will indicate the root of the repo. If I do this the deploy does not error but no files are deployed.
[Update]
I can see in the Get Sources of the Build the message "YOu are in 'detached Head' state. Maybe this has something to do with the problem.
[Update]
In the build pipeline I have
[Update]
When I try to create a new build pipeline I get the following
I select the location to be Azure Repos and the Repository to be vste
then I the azure-pipelines.yml auto-generates as
# ASP.NET Core
# Build and test ASP.NET Core web applications targeting .NET Core.
# Add steps that run tests, create a NuGet package, deploy, and more:
# https://learn.microsoft.com/vsts/pipelines/languages/dotnet-core
pool:
vmImage: 'Ubuntu 16.04'
variables:
buildConfiguration: 'Release'
steps:
- script: dotnet build --configuration $(buildConfiguration)
displayName: 'dotnet build $(buildConfiguration)'
[Update]
Looks like I might need to select Use The Visual Designer
[Update]
From ollifant's comment I have found the Publish Artifact task.
Now to figure out how to populate it
[Update]
Uh Uh not looking great
I had not used the ASP NET Core (.NET framework) template when creating the agent job in the build template, so the project was not building correctly.
New build pipeline -> Use the visual designer -> Continue -> ASP.NET Core (.Net Framework)
I have a dot net core 2.0 console app which I need to publish in Azure as webjob through continuous build and deployment in VSTS. I have created a web app already in Azure and defined CI and CD tasks in VSTS for the console app's project.
The issue is that whenever these tasks run, webapp gets deployed successfully but the webjob does not get deployed. However, it gets deployed when I use the artifact (zip folder created after build process) and upload it manually to Azure webjob section.
I think deploying the artifact using powershell script might be a solution but I have tried zipdeploy API of Kudu as well but to no use. Can someone please help or point me to a reference for extracting the artifact generated from build process and deploy it using CD tasks so that the webjob gets published alongwith webapp.
With general web application, if you link web job project to the web (right click web app in Visual Studio > Add > New Azure WebJob project/Existing project as WebJob), you can refer to these steps below:
Create a new build definition
Add NuGet Tool Installer task
Add NuGet restore task (Path to solution, packages.config: ***.sln)
Add Visual Studio Build task (MSBuild Arguments: /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\")
Add Publish Artifact task (Path to publish: $(build.artifactstagingdirectory))
Queue build
Create a new release definition
Add Deploy Azure App Service task (Package or folder: {web app zip file path}; Choose Publish using Web deploy)
Otherwise:
Create a new build definition
Add NuGet Tool Installer task
Add NuGet restore task (Path to solution, packages.config: ***.sln)
Add Visual Studio Build task (/p:DeployOnBuild=true /p:WebPublishMethod=FileSystem /p:publishUrl="$(build.artifactstagingdirectory)\" /p:DeployDefaultTarget=WebPublish
Add necessary task to build web job project (e.g. Visual Studio build)
Add Copy Files task to copy web job’ build result to appropriate folder in web app published folder ($(build.artifactstagingdirectory)) (App_Data/jobs/continuous for continuous webjobs or App_Data/jobs/triggered for scheduled and on-demand WebJobs)
Add Archive Files task (Root folder or file to archive: $(build.artifactstagingdirectory); Archive file to create: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip)
Add Publish Artifact task
Create a new release definition
Add Deploy Azure App Service task (Package or folder: {web app zip file path}; Choose Publish using Web deploy)
Setting up a Release definition task to deploy a MVC web app to a test server (on prem). Typically I have done this a FileSystem publish via a Visual Studio publish profile. What task can I use in VSTS to achieve the same thing, assuming I already have a working agent setup on the test server and a successful build?
The app is actually setup as a website on the test server, not a virtual app under another website. Looking at adding the "IIS Web App Deploy" task, VSTS reports that this task is "deprecated, so what is the suggested replacement for this?
I suppose I could use the Windows file copy task, but the build artifacts are zipped. What would I need to use if I went this route?
You can use Visual Studio Build task with /p:SkipInvalidConfigurations=true /p:DeployOnBuild=true /p:WebPublishMethod=FileSystem /p:publishUrl="$(build.artifactstagingdirectory)\\" /p:DeployDefaultTarget=WebPublish MSBuild Arguments to publish web app to artifact folder (e.g. {agent working folder}/1/a).
You also can specify the publish profile directly /p:SkipInvalidConfigurations=true /p:DeployOnBuild=true /p:PublishProfile="{publish profile name}";publishUrl="$(build.artifactstagingdirectory)"
With FileSystem publish method, the published files are in a folder, not zipped, but you can zipped the folder through Archive files task.
Also you can extract files through Extract files task, so you can copy extracted files through Window machine file copy task to the corresponding web site path.
On the other hand, you can deploy the web app through WinRM-IIS Web App Deployment task.
Trying to use a hosted build agent and an on-prem release agent.
Project is an ASP.Net MVC web app within a solution with other projects.
The build completes successful but there is nothing in the artifact folder so the release does nothing.
[ update 5/22/2018]
What I need to do is publish to some location relevant to the hosted agent, then in my on-prem release agent, be able to use a copy_files task to simply copy those files to a unc path.
[ update 5/23/2018]
Using these msbuild arguments on the build task, I was able to get a zipped folder containing the published files. The only problem now is that the files are in a deeply nested structure. So I either just need to unzip them on a release task, or prevent them from being zipped.
/t:My_MVCWeb_Project_Name /p:DeployOnBuild=true /p:WebPublishMethod=FileSystem /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\\"
Build log
Build task (Hosted VS 2017 agent). The /t parameter is followed by a project_name.
Publish task of Build definition
Release definition, with just a copyfiles task (this runs on-prem)
You need to use the default MSBuild Arguments in Build step since you use ASP.NET build template:
/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\\"
Or you need to add a Copy Files task before Publish Build Artifacts
to copy the files you need to path $(build.artifactstagingdirectory):
We are in process of creating architecture for VSTS CI/CD to deploy our web app to our Azure App Services.
We want to exclude the web.config while deploying it to the Azure server as we are directly modifying the web.config on the different environment.
CI Tasks looks like this:
CI Taks
CD Task:
Deploy Azure App Service
I am aware of other ways of updating the web.config https://learn.microsoft.com/en-us/vsts/build-release/tasks/transforms-variable-substitution, but in our case we want to skip the web.config file.
I couldn’t find the option to skip file in during release in VSTS as mentioned in this thread
How do I exclude the .cs files within an artifact from a vs-team-services CI build?
Is there a way to exclude certain files while building and deploying the release?
Added -skip:objectName=filePath,absolutePath=web\.config in additional arguments. This skips updating the web.config file during deployment.
You can exclude the web.config before publishing artifacts in your build definition: copy the web packages files to a directory (such as $(build.binariesdirectory)), then copy the files exclude web.config to another folder (such as $(Build.ArtifactStagingDirectory)/package), and zip the files under $(Build.ArtifactStagingDirectory)/package. And finally publish the zip file as build artifacts.
Details changes in the build definition as below:
Change the MSbuild arguments as /p:OutDir="$(build.binariesdirectory)\\" in Visual Studio Build task.
Add a Copy Files task after Visual Studio Build task. Settings for this task as below:
Add Archive Files task after Copy Files task. And settings as below:
Change the Publish Artifacts task as below:
Now the build artifacts are exclude web.config file.
Additional arguments
-skip:objectName=filePath,absolutePath=\\Configuration\\AppSettings\\Base.config
you can add
-skip:objectName=filePath,absolutePath='.*\PackageTmp\Web.config$'
in Additional Arguments in "Deploy IIS WebSite/App" deployment VSTS task, this will not deploy your root web.config file.