I created a release pipeline it is working very well but the XML transformation part is not working as I wanted.
I gave a name for my stage as "Development" and I have "Web.Development.config" file as I showed below, I checked the "XML transformation option" but not is changed. When I add "Web.Release.config" it works but I want to use "Web.Development.config" for the Development environment, I want to use "Web.Production.config" for the Production environment.
When I removed the "Web.Release.config" nothing happens.
When I added the "Web.Release.config" nothing happens. It is skipping or not using "Web.Development.config".
What am I missing? What is the wrong part?
After trying a lot of things, finally, I found a solution to my problem. These are the steps:
Go to your build definition, choose "Build Solution" task and add "/p:autoparameterizationwebconfigconnectionstrings=false" as an argument. If you don't do that, the xml transformation process will skip replacing "connectionString" attribute.
Make your all config files as content and mark them as copy always. After your edit, they should be like below in your project file. You should remove Web.config tag.
Go to your release definition and check the XML transformation option.
Make sure that you gave the same name to your stage with your *..config file.
You can check this link for more details: https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/transforms-variable-substitution?view=azure-devops
By default Azure DevOps uses your web.config and web.release.config and then applies an environment specific config. There is no way to exclude web.release.config from your transformations except from renaming/deleting the file.
See the docs on XML Transformation for all the details.
Related
In my repo I have a .net 5 web application project that (for now) references another library that is setup as an executable also. Both of these project have their own appsettings.json.
When I publish, I notice that the appsettings.json that ends up in the final folder is always the one from the project being referenced and not the one from the project actually being published. This seems truly odd behavior.
I realize the "right" approach is for the web app to not directly reference the other exe project (already have a story to fix that), but it is still a current concern.
Is there a command argument to have publish prefer appsettings.json from the project being published, as opposed to what seems like arbitrarily selecting one of multiple (or preferring the file from a lower dependency)?
For now, I suspect I can add an additional step to my build to copy the correct config file into place before the publish is "complete", but hoping for a better solution (one that doesn't require extra copy file steps).
Is there a command argument to have publish prefer appsettings.json from the project being published, as opposed to what seems like arbitrarily selecting one of multiple (or preferring the file from a lower dependency)?
The best solution is definitely to find the cause of this issue.
For example, if I add following setting in the project file actually being published:
<ItemGroup>
<Content Update="appsettings.json" CopyToPublishDirectory="Never" />
</ItemGroup>
Then the dotnet will publish the file appsettings.json from the project being referenced.
Of course, the cause of your problem may be other possibilities, which requires more actual information about your project to be able to know.
So, the current solution for this issue, you could add above settings for the project being referenced.
With above setting, the file appsettings.json from the project being referenced will not be published.
I'm completely new to Azure DevOps Pipelines so if I'm doing something incorrectly I'd appreciate a nod in the right direction... I setup a build pipeline and that seems to be working, now I'm trying to setup a release pipeline in order to run tests, it's mostly based on Microsoft's documentation:
https://learn.microsoft.com/en-us/azure/devops/test/run-automated-tests-from-test-hub?view=azure-devops
Before running tests I need to transform a config file to replace some variables like access keys, usernames, etc. What I setup is what I have below but for the life of me I can't figure out what text box Package or folder refers to. The documentation is super helpful as you can imagine:
File path to the package or a folder
but what package or what folder is this referring to??? I've tried several different things but everything errors with
##[error]Error: Nopackagefoundwithspecifiedpattern D:\a\r1\a\**\*.zip
or pretty much whatever I specify for a value.
The File Transform task supports the .zip files.
Test with the default File Transform task settings, I could reproduce this issue.
In Release pipeline, the file path could has one more node for the build artifacts .zip file.
The format example:
$(System.DefaultWorkingDirectory)\{Source alias name}\{Artifacts name}\*.zip
So you could try to set the $(System.DefaultWorkingDirectory)/**/**/*.zip in Package Or folder field
For example:
On the other hand, you can check the specific path in the Release log -> Download Artifacts Step.
$(System.DefaultWorkingDirectory): D:\a\r1\a
You could aslo use this specific path in the task.
Update:
If your file is Project Folder, you refer to the following sample:
File structure:
Task Settings:
Note:You only need to assign to the folder node.
You could also select the folder path via ... option.
I cloned an existing Build pipeline, where everything is the same except the variable values, however the XML transformation is not happening correctly, it's transforming using the incorrect file.
The QA pipeline works successfully, and looks like the below:
Pipeline variables:
Build solution step:
Log file showing transformation with "QA", which is correct:
The Dev pipeline is the exact same as above, but with different variable values:
Issue is that it's picking up "debug" file instead of "dev" file:
All config files exist in the branch I am building:
Any idea why the Dev pipeline is using Web.Debug.config instead of Web.Dev.config file during build process?
I figured out the issue. The transformation is happening as part of the build solution step - in the solution file. The issue is that someone had changed the configuration in the solution file so that every config defaulted to "Debug", except for QA, which was set correctly. Once I reverted that change, everything worked as expected.
Im setting up a new build and deploy pipeline in Azure Devops. It is an older Web application with some transformation files for the web.config. In the old days we would build the same code x times depending on how many environments. This this is no longer necesary as I read from here https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/transforms-variable-substitution?view=vsts#xmltransform
it looks like the deploy pipeline can pick up the changes from my transform file.
But the problem is that my other transform files does not get included in the package so I get these warning message:
[warning]Unable to apply transformation for the given package. Verify the following.
[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.
[warning]2. Ensure that the config file and transformation files are present in the same folder inside the package.
And yes when i download the artifact the Web.[stage].config files are not there as suggested.
Is there some setting somewhere that let me include these files? Or stop them from being transformed?
For Web applications
MSBuild knows how to transform the web.config files based on the following settings/properties/parameters (in order)
Build Configuration dotnet publish --configuration Release
Publish profile dotnet publish --configuration Release /p:PublishProfile=FolderProfile
Environment dotnet publish --configuration Release /p:EnvironmentName=Production
Custom file transform dotnet publish --configuration Release /p:CustomTransformFileName=custom.transform
I think it's typical for developers to make this happen based on build configuration only, and I believe MSBuild (and dotnet) know how to do this based on the <DependentUpon>Web.config</DependentUpon> element in the Web.[configuration].config item in the project or build script file.
Azure DevOps Release Pipelines is a little different.
The pipeline wants to transform your web.config after the project has been built/published and doesn't know how to do that if MSBuild (or dotnet) has already made an attempt at it. Thus:
[warning]Unable to apply transformation for the given package. Verify the following.
[warning]1. Whether the Transformation is already applied for the MSBuild generated package during build. If yes, remove the tag for each config in the csproj file and rebuild.
[warning]2. Ensure that the config file and transformation files are present in the same folder inside the package.
The warning text states:
Remove the <DependentUpon> tag for each config in the csproj
Thus: you need to remove the tag from the csproj to prevent MSBuild from transforming the files
Or: you need to use the /p:TransformWebConfigEnabled=False argument to MSBuild. (note: I believe it is correct that this can be used w/o removing the dependent upon tag, but I could be wrong)
Make sure the transform source and target files are in the same folder inside the package.
There may be several ways to do this. I've chosen to mark the transform source config files as content to force MSBuild to include them in the published package.
Now you need to organize your release pipeline in accordance with the File Transforms and Value Substitutions documentation.
[section]Starting: IIS Web App Deploy
====================================
Task : IIS Web App Deploy
Description : Deploy a website or web application using Web Deploy
Version : 0.0.51
Author : Microsoft Corporation
Help : More information
====================================
...[command]C:...\ctt\ctt.exe s:C:...\Web.config t:C:...\Web.Release.config d:C:...\Web.config pw i
[command]C:...\ctt\ctt.exe s:C:...\Web.config t:C:...\Web.Development.config d:C:...\Web.config pw i
XML Transformations applied successfully
...
For Non-Web Applications Needing .config Transformation
Getting your .config files to the release pipeline can happen several ways. Here are two.
Your release should have "access" to the repository as a part of the artifact, which will ensure that the deploy agent downloads the source (not desirable IMHO).
You will need to include the web.[stage].config files as part of your build artifact with a copy task, or a minimatch that picks them up.
Once you have the .config files available to the release pipeline
You can use the File Transform Task or XDT Transform Task to perform the transformation operations.
Option 2 is the route I've gone.
Here is an image of what that task looks like for me.
That task puts the config in the artifact from the build that I can then use in the release pipeline without rebuilding xx times.
Cleanup
If you're in a position where you care to not have the transform files persisting on the agent after the release is complete, then you'll need to add that to your pipeline.
I am using TeamCity and I am new to it. I have added a Build Configuration to the TeamCity and I created one VCS root to attach to it.
However, my project have a special requirement to detect a particular file that was changed in the VCS root location and use that file in build step. I am sure this could be done in TeamCity, I am not able to figure out how.
Any help? Thanks,
To get the names of the files changed this is what I did. Thanks to Sam Jones.
I used System.TeamCity.build.changedFiles.file variable as follows.
Add a command line build step
Select Run as Custom Script
Add the script copy "%system.teamcity.build.changedFiles.file%" changelog.txt in script box.
You will get the changes in changelog.txt file in the format specified on this link.
NOTE: teamcity.build.changedFiles.file does not work. You need to use system.teamcity.build.changedFiles.file
It sounds like you want a VCS Trigger that specifies VCS Trigger Rules, so that a build configuration will run when someone makes a change to a particular file. The documentation has some nice examples of how to do this. If you're trying to trigger a build on one particular file, try this:
+:foo/bar.txt
This excludes all files from the trigger rule and then includes bar.txt in the foo directory. Paths are relative to the root of the repository (do not include a preceding slash). If someone modifies foo/bar.txt, the build configuration will be triggered to run.
VCS Trigger Rules also support pattern matching and all sorts of other options. Check out the documentation.