How to do IIS Deployment with XML Transformation in Azure-DevOPS Release pipeline? - azure-pipelines-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)

Related

How to perform web.config transformation in 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.

Error when trying to Scaffold a model

I'm building a Razor Page app using ASP.NET 2017. When I run the command
dotnet aspnet-codegenerator razorpage -m Activity -dc CongContext -udl -outDir Page\Activities --referenceScriptLibraries
This error appears:
Could not load file or assembly 'Microsoft.EntityFrameworkCore,
Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
The located assembly's manifest definition does not match the assembly
reference. (Exception from HRESULT: 0x80131040)
I stopped and restarted VS, I've also cleaned and build the solution. Attached jpg shows the code I typed and the results
This is because of different versions of packages. Check the 'Dependencies' node of your project. The Microsoft.EntityFrameworkCore and Microsoft.EntityFrameworkCore.Design must have same 2.0.3 versions.
If not, delete and re-add them from [Tools] menu > [Nuget Package Manager]. Also delete the Migrations folder and repeat instructions as listed here. For more info, you may take a look at this comment

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}

ClassNotFoundException: com.mysql.jdbc.Driver (jar already in buildpath) [duplicate]

Could someone provide a few details on how to configure Tomcat to access MySQL?
In which directory within Tomcat do I place mysql-connector-java-5.1.13-bin? Should I place it under Tomcat 6.0\webapps\myapp\WEB-INF\lib?
Do I need to add configuration to context.xml or server.xml?
Should I create a web.xml file and place it under Tomcat 6.0\webapps\myapp\WEB-INF? If so, then what should the contents of this file look like?
1: Where to place mysql-connector-java-5.1.13-bin in Tomcat directory? Should I place it under Tomcat 6.0\webapps\myapp\WEB-INF\lib?
That depends on where the connections are to be managed. Normally you would like to create a connection pooled JNDI datasource to improve connecting performance. In that case, Tomcat is managing the connections and need to have access to the JDBC driver. You should then drop the JAR file in Tomcat/lib.
But if you're doing it the basic way using DriverManager#getConnection(), then it in fact don't matter if you drop it in Tomcat/lib or YourApp/WEB-INF/lib. You however need to realize that the one in Tomcat/lib will apply for all deployed webapps and that the one in YourApp/WEB-INF/lib will override the one in Tomcat/lib for only the particular webapp.
2: Do I need to confirgure context.xml or server.xml files?
That depends on where the connections are to be managed. When using a JNDI datasource, it suffices to configure it using YourApp/META-INF/context.xml like follows (just create file if not exist):
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Resource
name="jdbc/yourdb" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
url="jdbc:mysql://localhost:3306/yourdb"
driverClassName="com.mysql.jdbc.Driver"
username="yourname" password="yourpass"
/>
</Context>
and the YourApp/WEB-INF/web.xml as follows:
<resource-env-ref>
<resource-env-ref-name>jdbc/yourdb</resource-env-ref-name>
<resource-env-ref-type>javax.sql.DataSource</resource-env-ref-type>
</resource-env-ref>
If you're doing it the basic DriverManager way, then it's all up to you. Hardcoded, properties file, XML file, etcetera. You should manage it youself. Tomcat won't (and can't) do anything useful for you.
Noted should be that the YourApp/META-INF/context.xml is specific to Tomcat and clones. Each servletcontainer/appserver has its own way of defining JNDI resources. In Glassfish for example, you'd like to do that through the webbased admin interface.
3: Should I write web.xml file and need to place under Tomcat 6.0\webapps\myapp\WEB-INF? If Yes, then what should be the contents of file?
You should always supply one. It's not only to configure resources, but also to define servlets, filters, listeners and that kind of mandatory stuff to run your webapp. This file is part of the standard Servlet API.
See also:
Is it safe to use a static java.sql.Connection instance in a multithreaded system?
How should I connect to JDBC database / datasource in a servlet based application?
Where do I have to place the JDBC driver for Tomcat's connection pool?
DAO Tutorial - basic JDBC/DAO tutorial, targeted on Tomcat/JSP/Servlet
The answer to your questions:
One option is what you've mentioned: place the driver under WEB-INF/lib directory in your WAR file. The other would be in $TOMCAT_HOME/lib directory. The advantage of the latter would be that you don't need to copy the connector jar into every single project you deploy on that application server. Disadvantage is you will need to remember to put the jar file in place before deploying your application in a different application server.
If you need to change something in the default configuration, yes. Otherwise, there are context.xml and server.xml files with default options shipped with tomcat installations.
Your application's (WAR) web.xml should be under WEB-INF directory in your deploy file. You can look at the accepted content to that file in Java EE's servlet container specification. Usually, you place your servlet, filter and their corresponding mappings in that file.

Error thrown by SSIS package : The input Web Services Description Language (WSDL) file is not valid

Im trying to connect to a web service using Web Service task. I have used the WsdlFile property to dynamically set the path of WSDL file.
The package executes fine on my local system. When I try to execute the same package on my TEST server ( via Active Batch scheduler), it fails with the following exception :
-1073548540,0x,An error occurred with the following error message: "Microsoft.SqlServer.Dts.Tasks.WebServiceTask.WebserviceTaskException: The input Web Services Description Language (WSDL) file is not valid.
I have placed the WSDL file in my TEST server location ( which is equal to the path set in WsdlFile property) and also have Delay Validation = True on WebService task in the package.
Kindly help on how can I resolve this issue.
In my experience this will only occur if the WSDL file is invalid (obviously!) or the SSIS package can't find the WSDL file. Ensure that your configuration exposes the WsdlFile property.
To do so, select SSIS > Package Configurations, and create or edit an existing configuration. Tick the WsdlFile property to expose it:
This will add a property to a configuration file. Ensure that the value of that is set to a full file path e.g. "D:\SSIS\WebService.wsdl"
Finally, once deployed, ensure that your SSIS package references the configuration file you've created.