How to perform web.config transformation in release pipeline - azure-pipelines-release-pipeline

I have a build pipeline which publishes a build artifact to path $(Build.ArtifactStagingDirectory). I have a release pipeline with 1 stage following the IIS website deployment template. The IIS web App Deploy task is set to use Xml Transformation, and the deployment executes successfully. The website is created in IIS, but the web.config is not transformed correct.
My Stage is called "MyEnvironment", and I have a web.config and a web.MyEnvironment.Config file in the project, which transforms correctly in visual studio transform preview and if I publish from visual studio. If I look at the logs for my release pipeline, I see that the IIS Web App Deploy task executed successfully but there were warnings:
2022-02-09T19:05:07.5762631Z ##[warning]Unable to apply transformation for the given package. Verify the following.
2022-02-09T19:05:07.5773252Z ##[warning]1. Whether the Transformation is already applied for the MSBuild generated package during build. If yes, remove the <DependentUpon> tag for each config in the csproj file and rebuild.
2022-02-09T19:05:07.5775568Z ##[warning]2. Ensure that the config file and transformation files are present in the same folder inside the package.
My understanding was that the xml transformation of an IIS Web App Deploy task would use the name of the stage as the environment when searching for the web.config transform to use. I'm sure that the stage name matches the web..config file, yet it is still not transforming correctly. Is there something I'm missing here?
trigger:
- Development
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild#1
inputs:
solution: '$(solution)'
# msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)" /p:AutoParameterizationWebConfigConnectionStrings=False'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: VSTest#2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'

You will need to turn off the transforms during the build in the yml and in the project file.
In your yml file under the VSBuild#1 task in you msbuildArgs add /p:TransformWebConfigEnabled=false
In your project file find
<Content Include="web.MyEnvironment.config">
<DependentUpon>web.config</DependentUpon>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
And remove the <DependentUpon>web.config</DependentUpon> but make sure <CopyToOutputDirectory>Always</CopyToOutputDirectory> is there, you may need to add it.
When you build, your web.config and web.MyEnvironment.config should both be in the drop artifacts at the base level of your web app as well as in the bin folder, not just in the bin folder. The rest of your settings should be correct. You can reference this question as well.

Related

Unable to build SSRS Project

I am trying to set up a build pipeline in Azure DevOPS to build a SSRS project. I have a VSBuild task setup like so
- task: VSBuild#1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:OutDir="bin\Debug" /p:OutputPath="bin\Debug" /verbosity:diagnostic'
configuration: '$(configuration)'
I am getting the following error
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Reporting
Services\Microsoft.ReportingServices.MSBuilder.targets(30,5): Error
MSB4018: The "ReportBuilderTask" task failed unexpectedly
System.ArgumentException: The OutputPath property cannot be blank. It
must provide a relative path that is a child folder under the path of
the report server project. at
Microsoft.ReportingServices.BuildProcess.ReportProjectOptions.GetOutputDirectory()
at
Microsoft.ReportingServices.BuildProcess.ReportProjectOptions.GetOutputFile(String
fileName) at
Microsoft.ReportingServices.BuildProcess.Builder.BuildReport(ReportReportNode
node, ReportProjectOptions options, IMessageHandler messageHandler,
ICheckPublish checkPublish) at
Microsoft.ReportingServices.BuildProcess.Builder.BuildItems(ICollection
collection, ReportProjectOptions options, IMessageHandler
messageHandler, ICheckPublish checkPublish) at
Microsoft.ReportingServices.BuildProcess.ReportBuilderTask.Execute()
at
Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
I checked the PropertyGroup for my configuration and I do see OutputPath, I am also supplying it as an MSBuild parameter additionally, but it isn't getting picked up it seems.
What am I missing? I am using the hosted agent.
As stated in the error message, the path cannot be full path. The azure devops variables carry full absolute paths. I have changed the OutputPath property to carry the relative path and things seem to work now.

How to do IIS Deployment with XML Transformation in Azure-DevOPS Release pipeline?

How to create a release pipeline for IIS Deployment with XML Transformation
I create a build pipeline in azure devops.I am planning to create a release pipeline which needs to deploy the build in 3 IIS Websites(DEV,QA,STAG) to on Premise Servers (iam not using Azure servers)
As per my research, i created 3 configs in the application with their environment specific values in each config
When i use the IIS Deploy task,i have an option to select the xml transformation.How does the xml transformation works?
Xml transformation takes effect only when the configuration file(web.config) and transform file(web.stage.config) are in the same folder within the specified package. For more information you can check this official site
The transform file is an XML file that specifies how the Web.config file should be changed when it is deployed. For its syntax you can check this(https://learn.microsoft.com/en-us/previous-versions/aspnet/dd465326(v=vs.110))
So in your case, Firstly you should specify a configuration file (eg. Web.config) and three transform files, the transform file should be named after its environment configuration(eg. web.dev.config, web.qa.config, web.stag.config).
In the these three transform files, specify the elements and attributes that need to be transformed with XDT syntax(check above syntax link)(XML-Document-Transform).
Secondly: you should create three stages named dev, qa, stag respectively in your release pipeline.
Thirdly: enable XML transformation of IIS Web App Deploy task for each stage.
Hope you can find above helpful?
Refer to these steps below:
Step 1: Create a Asp.net Web Application (Name:SalesDemo)
Step 2.1: Create Nested Configs (e.g. web.SalesDemoQA.config, web.SalesDemoStag.config,web.SalesDemoProd.config), Copy to Output Directory: Always)
Sept 2. 2 open your csproj file in a text editor and check the following
<None Include="web.SalesDemoQA.config">
<DependentUpon>web.config</DependentUpon>
</None>
change the above code to the below code
<Content Include="web.SalesDemoQA.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content >
Step 2.3 Sample code in web.SalesDemoQA.config
<connectionStrings>
<add name="SalesDemo" connectionString="Data Source=ReleaseSQLServer;Initial Catalog=SalesDemoDBQA;Integrated Security=True"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
Step 3: Login to Azure DevOPS site
Step 4: Create Build Pipeline
Step 4.1: Select a Repsotiory
Step 4.2: Select a Template (Asp.net Template)
Sep 4.3 msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:TransformWebConfigEnabled=False /p:AutoParameterizationWebConfigConnectionStrings=False /p:PackageLocation="$(build.artifactstagingdirectory)\\"'
platform: '$(BuildPlatform)'
configuration: '$(BuildConfiguration)'
Note: I added the following additional parameters in the msBuildArgs
/p:TransformWebConfigEnabled=False /p:AutoParameterizationWebConfigConnectionStrings=False
Step 4.4: Publish Build Artifacts
Step 5 Create a Release pipeline
Step 5.1:Create a Stage Name:(SalesDemoQA)
Step 5.2 :Create IIS Web App Manage Task
Step 5.3 :Create IIS Web App Deploy Task
Step 5.4 :Set the (Package or Folder: $(System.DefaultWorkingDirectory)/_SalesDemo/drop/SalesDemo.zip;
Step 5.5 :Check XML transformation option
Assuming that the web.SalesDemoQA.config file will be transformed to web.config file.
Note :The Stage Name matches with the config name(www.salesDemo.config)

Can a jlinked runtime be deployed with javapackager?

The instructions to javapackager just above Example 2-1 in the Java SE Deployment Guide/Self-Contained Application Packaging state that a jar file is required in the -deploy command.
If I use a modular jar, I get this error message:
Exception: java.lang.Exception: Error: Modules are not allowed in srcfiles: [dist\tcdmod.jar].
If I use the equivalent non-modular jar, the resulting package includes the complete runtime. But I want to use the reduced runtime I made with jlink that is in the /dist folder.
Can the javapackager command deploy with a jlink-generated runtime?
How?
The section titled "Customization of the JRE" makes no mention of the javapackager command.
The following section "Packaging for Modular Applications" has a following line:
Use the Java Packager tool to package modular applications as well as non-modular applications.
Is the Java Packager tool distinct from javapackager? There are no examples using javapackager in this section.
Here is the javapacker command that I used:
javapackager -deploy -native -outdir packages -outfile ToneCircleDrone -srcdir dist -srcfiles tcdplain.jar -appclass com.adonax.tanpura.TCDLaunch -name "ToneCircleDrone" -title "ToneCircleDrone test"
The instructions in the javapackager documentation make no mention of the scenario where a jlink runtime is used. There is a Bundler argument -Bruntime but it is only used to point to an installed runtime other than the system default, AFAIK.
The javapackager provided with JDK 9 and up uses jlink to generate the jre image:
For self-contained applications, the Java Packager for JDK 9 packages
applications with a JDK 9 runtime image generated by the jlink tool. To
package a JDK 8 or JDK 7 JRE with your application, use the JDK 8 Java
Packager.
https://docs.oracle.com/javase/9/tools/javapackager.htm#JSWOR719
You can even pass arguments to jlink using -BjlinkOptions=<options>
Additionally, -Bruntime is only valid for packages deployed using -deploy -native jnlp
For compiling a modular application, instead of -srcdir, use --module-path <dir>, and then specify the main module using -m <module name>.
EDIT: While there is no documentation on -BjlinkOptions, it is present in the javapackager source
jdk.packager/jdk.packager.internal.legacy.JLinkBundlerHelper
https://github.com/teamfx/openjfx-10-dev-rt/blob/bf971fe212e9bd14b164e4c1058bc307734e11b1/modules/jdk.packager/src/main/java/jdk/packager/internal/legacy/JLinkBundlerHelper.java#L96
Example Usage: -BjlinkOptions=compress=2 will make javapackager run jlink with the --compress=2 flag, generating the JRE image with Zip Level compression.
Aditionally, running javapackager with the flag -Bverbose=true will show you exactly which arguments are being passed to jlink with a line in the output something like this:
userArguments = {strip-debug=1 compress=2}

polymer-cli build fails for element starter template

I am trying to create a reusable component using polymer cli.
I would like to use this component into another project where i can include it as a single file import.
But when I am trying to build the project, it keeps failing.
Below are details of my environment.
$node --version
v4.6.0
$ npm --version
2.15.9
$ polymer --version
0.16.0
$ polymer init
? Which starter template would you like to use? element
info: Running template element...
? Element name (my-el)
$polymer build
$ polymer build
info: Building application...
info: Generating build/unbundled...
info: Generating build/bundled...
error: Uncaught exception: Error: file path is not in root: /Users/yogeshkulkarni/workspace/polymer/polymer/polymer.html (/Users/yogeshkulkarni/workspace/polymer/my-el)
error: Error: file path is not in root: /Users/yogeshkulkarni/workspace/polymer/polymer/polymer.html (/Users/yogeshkulkarni/workspace/polymer/my-el)
at Object.urlFromPath (/usr/local/lib/node_modules/polymer-cli/node_modules/polymer-build/lib/path-transformers.js:41:15)
at StreamAnalyzer.getFile (/usr/local/lib/node_modules/polymer-cli/node_modules/polymer-build/lib/analyzer.js:107:39)
at StreamResolver.accept (/usr/local/lib/node_modules/polymer-cli/node_modules/polymer-build/lib/analyzer.js:210:34)
at FileLoader.request (/usr/local/lib/node_modules/polymer-cli/node_modules/polymer-build/node_modules/hydrolysis/lib/loader/file-loader.js:64:27)
at Analyzer.load (/usr/local/lib/node_modules/polymer-cli/node_modules/polymer-build/node_modules/hydrolysis/lib/analyzer.js:121:32)
at Analyzer._getDependencies (/usr/local/lib/node_modules/polymer-cli/node_modules/polymer-build/node_modules/hydrolysis/lib/analyzer.js:433:25)
at Analyzer._dependenciesLoadedFor (/usr/local/lib/node_modules/polymer-cli/node_modules/polymer-build/node_modules/hydrolysis/lib/analyzer.js:401:25)
at Analyzer._parseHTML (/usr/local/lib/node_modules/polymer-cli/node_modules/polymer-build/node_modules/hydrolysis/lib/analyzer.js:227:50)
at null._onTimeout (/usr/local/lib/node_modules/polymer-cli/node_modules/polymer-build/node_modules/hydrolysis/lib/analyzer.js:125:39)
at Timer.listOnTimeout (timers.js:92:15)
polymer-cli build works fine when I choose application starter template. Is polymer-cli doesn't support building element starter template?
I had similar problems. I used the polymer INIT - 'a blank application template', to create my project.
Which didn't provide a polymer.json configuration file. I added and configured this file. Now polymer BUILD is without any errors (in my project). Because polymer BUILD needs to know about your project structure. See https://www.polymer-project.org/1.0/toolbox/server
The docs for polymer-cli state:
This command is for app projects only.
And it currently doesn't provide a user-friendly error message for this scenario, so you'll see it crash with a stack trace when building element projects.

MSDeploy gulp build package

Is it possible to deploy a Single Page App project build using grunt to IIS using MSDeploy from TeamCity? The project is not any kind of Visual Studio solution and doesn't get built using MSBuild.
My Command parameters which are not working are:
-source:package='%teamcity.build.checkoutDir%\Dist.%build.number%.zip' -dest:auto,computerName="%system.MsDeployServiceUrl%",userName="%system.UserName%",password="%system.Password%",authtype="basic",includeAcls="False"
-verb:sync -setParamFile:"%teamcity.build.checkoutDir%\Dist.%build.number%.zip.SetParameters.xml"
-AllowUntrusted -setParam:"IIS Web Application Name"="%system.WebSiteName%" -verbose
The error I am getting is:
[11:47:31][Step 3/3] Error Code: ERROR_EXCEPTION_WHILE_CREATING_OBJECT
[11:47:31][Step 3/3] More Information: Object of type 'package' and
path 'D:\TeamCity\buildAgent\work\e2b0015b49d87e90\Dist.30.zip' cannot
be created. Learn more at:
http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_EXCEPTION_WHILE_CREATING_OBJECT.
[11:47:31][Step 3/3] Error: The Zip package
'D:\TeamCity\buildAgent\work\e2b0015b49d87e90\Dist.30.zip' could not
be loaded. [11:47:31][Step 3/3] Error: Could not find file
'D:\TeamCity\buildAgent\work\e2b0015b49d87e90\Dist.30.zip'.
[11:47:31][Step 3/3] Error count: 1. [11:47:31][Step 3/3] Process
exited with code -1 [11:47:31][Step 3/3] Step Deploy (Command Line)
failed
My build process is working as I end up with the correct artefacts, I just don't seem to be able to deploy my generated artefacts using MSDeploy
This is a screenshot of my artefacts:
I managed to get this working by changing my parameters to the following:
-source:iisapp='%teamcity.build.checkoutDir%\dist' -dest:iisapp='C:\www\xxxx-website',computerName="%system.MsDeployServiceUrl%",userName="%system.UserName%",password="%system.Password%",authtype="basic",includeAcls="False"
-verb:sync -AllowUntrusted -verbose
And changing my user to an admin user rather than an IIS user. Note use of iisapp - the key was to read the MSDeploy api using msdeploy -help
FYI - a good test is to use the intended command against msdeploy.exe in console and check output errors then push command into teamcity when it's working.
I created a grunt and gulp plugin to do just what you are looking to do. gulp-mswebdeploy-package and grunt-mswebdeploy-package will create a ms webdeploy package from any folder and do not require your build to be running on windows.
https://www.npmjs.com/package/gulp-mswebdeploy-package
https://www.npmjs.com/package/grunt-mswebdeploy-package