How to override the keys in windows services .exe.config file through VSTS release definition - deployment

I am working on VSTS release task for deploying the Windows Services Project. Unfortunately, we are not creating any Build Definition for creating drop folder.
But, my client will provide drop folder for this project, what I need is “I want to override the keys of an existing .exe.config file” at release level.
For creating the Windows Services Deploy task,I followed this Windows Services Extension
For example my drop folder looks like below:
Many thanks for this reference article and It's a very useful for changing values in config file using Power Shell commands. I have doubt in from that reference link :
For Example, If had a Code like this :
<erecruit.tasks>
<tasks>
<task name="AA" taskName="AA">
<parameters>
<param key="connectionString">Server="XXXX"</param>
</parameters>
</task>
How to change this above connectionstring value?

You can use Tokenizer task in Release Management Utility tasks extension.
Install Release Management Utility tasks extension
Add Tokenizer with XPath/Regular expressions task to release definition (Specify Source filename and Configuration Json filename)
Config file sample:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="TestKey1" value="__Token1__" />
<add key="TestKey2" value="__Token2__" />
<add key="TestKey3" value="__Token3__" />
<add key="TestKey4" value="__Token4__" />
</appSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>
Configuration Json file (Default Environment is the environment name in release definitioin):
{
"Default Environment":{
"CustomVariables":{
"Token2":"value_from_custom2",
"Token3":"value_from_custom3"
},
"ConfigChanges":[
{
"KeyName":"/configuration/appSettings/add[#key='TestKey1']",
"Attribute":"value",
"Value":"value_from_xpath"
}
]
}
}
Then the value of TestKey1 (key) will be related to value_from_xpath and the values of TestKey2 and TestKey3 will be related to value_from_custom2 and value_from_custom3.
On the other hand, you can use release variables directly if you don’t specify Configuration Json filename.
For example, there is __TokenVariable1__ in your config file and TokenVariable1 release/environment variable in release definition, then the __TokenVariable1__ will be replaced through Tokenizer task.
A related article: Using Tokenization (Token Replacement) for Builds/Releases in vNext/TFS 2015
Update:
You also can do it through PowerShell directly.
Update configuration files using PowerShell

Related

Azure pipeline release deploy xml transformation question

I have an azure web site, and an application that i have set up via VSTS to build/release to this site. I'm using the Azure app service deploy task ( https://github.com/Microsoft/azure-pipelines-tasks/blob/master/Tasks/AzureRmWebAppDeploymentV4/README.md ) and i need to be able to transform the web.config based on library variable settings.
The basic transformations are easy, i have no problem just replacing the connection strings and the app settings. There are however, more difficult settings that i need to change. for example:
<sessionState mode="InProc"/>
<sessionState mode="Custom" customProvider="RedisStateStore" cookieless="false" regenerateExpiredSessionId="true">
<providers>
<add name="RedisStateStore" applicationName="XXX" type="YYY"/>
</providers>
</sessionState>
<sessionState cookieless="false" regenerateExpiredSessionId="true" mode="Custom" customProvider="SqlSessionStateProviderAsync">
<providers>
<add name="SqlSessionStateProviderAsync" connectionStringName="SQLSessionConnectionString" type="Microsoft.AspNet.SessionState.SqlSessionStateProviderAsync, Microsoft.AspNet.SessionState.SqlSessionStateProviderAsync, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</providers>
</sessionState>
based on settings in my deployment library variables, i need to be able to configure the session state to be one of the three above, and edit the appropriate settings accordingly (the variables inside the redis provider for example can change.
Additionally i need to edit more files than just the web.config. What are good ways to do this?

Publishing ASP.NET Core application to Azure via PowerShell getting 502 (Bad Gateway) In Azure

How can I publish my ASP.NET Core application to Azure?
What I have done so far is created a script that I got from official Azure/Microsoft documents that call on default-publish.ps1 script that Visual Studio also uses. The script looks as follows:
param($websiteName, $packOutput)
$website = Get-AzureWebsite -Name $websiteName
# get the scm url to use with MSDeploy. By default this will be the second in the array
$msdeployurl = $website.EnabledHostNames[1]
$publishProperties = #{'WebPublishMethod'='MSDeploy';
'MSDeployServiceUrl'=$msdeployurl;
'DeployIisAppPath'=$website.Name;
'Username'=$website.PublishingUsername;
'Password'=$website.PublishingPassword}
$publishScript = "${env:ProgramFiles(x86)}\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\Publish\Scripts\default-publish.ps1"
. $publishScript -publishProperties $publishProperties -packOutput $packOutput
Now this script calls upon the default-publish.ps1 script, given you provide the Azure website name and the dotnet publish artifact. I have updated my default-publish.ps1 script to exactly what is currently in the repo.
The issue is that when I publish to Azure a 502 Bad Gateway error is returned. Even with a project created using the new tooling update, I cannot seem to publish it to Azure correctly.
Do you have a web.config? Is it included in your project.json like this:
"publishOptions": {
"include": [
"wwwroot",
"web.config"
]
}
Your web.config will look something like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule"
resourceType="Unspecified"/>
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%"
stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout"
forwardWindowsAuthToken="false"/>
</system.webServer>
</configuration>
Note: The environment variables LAUNCHER_PATH and LAUNCHER_ARGS may be the source of your issue. You are attempting to launch the publishing scripts that visual studio runs, it is possible that visual studio sets the values in the environment before running the scripts.
To get an RC2 site up and running on an Azure VM, I had to change that line to look like this:
<aspNetCore processPath="dotnet" arguments="./YourAppEntryPoint.dll"
stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout"
forwardWindowsAuthToken="false"/>
Try setting your web.config with the explicit values. If your deploy works, then you know it's the missing ENVVARS that are messing it up.

getting setting from web.config in sitecore

i want to get global setting from web.config file in sitecore solution,
i write setting in config file and able to see it's entry in showconfig. when i try to get it's value, it is not giving appropriate value. my code is like this:
var newsBodyTemplateID = Sitecore.Configuration.Settings.GetSetting("NewsBody");
when i evaluate this, it giving this message:
what i'm missing here can some figure out it.
First of all I don't recomment to add in web.config your settings. If you want to upgrade your Sitecore than you have to merge manually your web.config.
If you still want to add setttings in web.config you need to have something like :
<configuration>
.....
<appSettings>
<add key="YourSeetings" value="your value" />
...
</appSettings>
.....
</configuration>
From C# code you need to use
ConfigurationManager.AppSettings["YourSeetings"]
If you have your settings on section /configuration/sitecore/settings
you need to use from C# code :
Sitecore.Configuration.Settings.GetSetting("yoursettingsname");
Your config file will looks like :
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/">
<sitecore>
<!-- General settings -->
<settings>
<setting name="YourSettingsFieldName" value="{1EPR25B2-98C6-45BF-B9E4-824ECAAEF499}" />
</settings>
</sitecore>
</configuration>
That method will return settings from the Sitecore\Settings node. there is another method to get AppSettings.
Sitecore.Configuration.Settings.GetAppSetting()

Function imports for entity framework with odp.net managed driver

I recently switched from ODP Unmanaged to ODP Managed (in conjunction with Entity Framework).
The Unmanaged drivers were working fine after adding the necessary information in the web.config section. I could add the stored procedures and generate the complex types using the Function Import - Get Column information (I'm trying to import a stored procedure with an OUT refcursor parameter).
After the switch the config section was updated to reflect the new format and everything works at runtime (so the format is correct).
However when I try to generate the complex types again (or add a new Function Import) I just get a System.notSupportedException Message: The specified type is not supported by this selector) Without any indication which type/selector it is (obviously)...
Google has turned up nothing and the thread on the Oracle Forums has gathered no response as well.
Versions:
ODP.Net (ODAC) : v12.1 (Production release; DLL v4.121.1.0)
EF v5
.NET v4.5
Config file (trimmed a bit):
<configSections>
<section name="oracle.manageddataaccess.client" type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess"/>
</configSections>
<oracle.manageddataaccess.client>
<version number="*">
<edmMappings>
<edmMapping dataType="number">
<add name="bool" precision="1"/>
<add name="byte" precision="2" />
<add name="int16" precision="5" />
<add name="int32" precision="10" />
<add name="int64" precision="38" />
</edmMapping>
</edmMappings>
<implicitRefCursor>
<storedProcedure schema="ECOM" name="SHP_API_ORDERS.CREATE_ORDER">
<refCursor name="O_RS">
<bindInfo mode="Output"/>
<metadata columnOrdinal="0" columnName="COL1" nativeDataType="Number" providerType="Decimal" allowDBNull="false" numericPrecision="10" numericScale="0" />
<metadata columnOrdinal="1" columnName="COL2" nativeDataType="Date" providerType="Date" allowDBNull="true" />
<metadata columnOrdinal="2" columnName="COL3" nativeDataType="Varchar2" providerType="Varchar2" allowDBNull="false" columnSize="10" />
</refCursor>
</storedProcedure>
</implicitRefCursor>
</version>
</oracle.manageddataaccess.client>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="Oracle.ManagedDataAccess.Client" />
<add name="ODP.NET, Managed Driver"
invariant="Oracle.ManagedDataAccess.Client"
description="Oracle Data Provider for .NET, Managed Driver"
type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess, Version=4.121.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
</DbProviderFactories>
</system.data>
The implicit ref cursor config file format is different between Unmanaged ODP.NET and Managed ODP.NET. That might be part of your problem.
To save yourself from pulling your hair out, install the latest Oracle Developer Tools for Visual Studio (ODT) and use the new feature that automatically generates this config:
1) Install ODT 12.1 if you haven't already
2) Find the stored procedure in server explorer, right click it and run it, and enter input parameters.
3) For the output ref cursor that represents the return value for your Entity Function, choose "Add to Config" checkbox.
4) Then select either "Show Config" (and then cut and paste) or "Add to Config".
Here is a screenshot of what I am talking about:
http://i.imgur.com/t1BfmUP.gif
If this doesn't fix the problem, play around with that boolean mapping. I am not 100% sure of this as of this writing, but I remember hearing that support for booleans is another difference between managed and unmanaged ODP.NET. I'm sure it's buried in the release notes or doc somewhere.
Christian Shay
Oracle
Two things you would want to try which might potentially solve the issue:
Ensure the case of the schema name, stored procedure name and the
column names in the config are the same as that in the Oracle.
Try mapping the native type to a more conformant provider type, like
the first column COL1 - map an int32 providerType to the
number(10,0) nativeDataType as enforced by your edmmapping, instead of
the Decimal that you currently have. And so forth for the other
columns (like remove the column lengths) until you do not see the error or get a different one.
I've got the same error and I think my problem is a providerType of DOUBLE or DECIMAL. But, I got one to work that has your 3 column types. Your problem is that a number(10,0) should be a providerType of "Int64".
Stored Procedure:
create or replace PROCEDURE "PROC_ESCC_FIELDS" (p_recordset OUT SYS_REFCURSOR)
AS
BEGIN
OPEN p_recordset FOR
SELECT COL1, COL2, COL3
FROM MyTable;
END PROC_ESCC_FIELDS;
This works and returns the cursor:
<oracle.manageddataaccess.client>
<version number="*">
<implicitRefCursor>
<storedProcedure schema="SERFIS" name="PROC_V_SERFIS_ESCC_FIELDS">
<refCursor name="P_RECORDSET">
<bindInfo mode="Output" />
<metadata columnOrdinal="0" columnName="COL1" providerType="Int64" allowDBNull="false" nativeDataType="Number" />
<metadata columnOrdinal="1" columnName="COL2" providerType="Date" allowDBNull="true" nativeDataType="Date" />
<metadata columnOrdinal="2" columnName="COL3" providerType="Varchar2" allowDBNull="false" nativeDataType="Varchar2" />
</refCursor>
</storedProcedure>
</implicitRefCursor>
</version>
</oracle.manageddataaccess.client>
Click here for a list of the providerType and nativeDataType, etc. ENUMS:

multiple applications single config file

I'm trying to write a service and configuration application. VB/C++ 2010 I've had a number of hits on google but they largely seem to be obsolete. What I have so far is a project with a single form app and a service app. The single form app has an "app.config" file and I have added a section:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings file="settings.config">
</appSettings>
</configuration>
In the Solution I have added a "settings.config" file and its contents is:
<?xml version="1.0" encoding="utf-8"?>
<appSettings>
<add key="Setting1" value="This is Setting 1 from settings.config" />
<add key="Setting2" value="This is Setting 2 from settings.config" />
<add key="ConnectionString" value="ConnectString from settings.confg" />
</appSettings>
I have added a reference to then C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\Profile\Client\System.Configuration.dll
library in both the forms app and the service app
In the very simple forms app i have the following code
Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Dim s As String = _
System.Configuration.ConfigurationManager.AppSettings("ConnectionString")
TextBox1.Text = s
End Sub
It doesn't work! Now clearly I am missing something. Its probably very simple. But my limited understanding is that this is automatically configuered by the config files I have? MS in their usual helful fashion seem to only give samples for 2012 and net 4.5 or greater. I need this to work on a 2003 server (as well) so I'm limited to net 4.0
The problem here is that the line System.Configuration.ConfigurationManager.AppSettings("ConnectionString") is looking for the key ConnectionString in your application's app.config file.
The fact that you have included that file key in your app.config file doesn't magically tell the ConfigurationManager to load the settings from a different file. If that's what you want you will have to read the setting for the file key and then manually load the configuration from that file.
This has not changed since the early versions of .Net though so I'm not sure why you were conflicted by the examples.
Add reference on existing assembly in .Net section of your Add Reference Popup
But i suggest you to use connectionStrings section in your config file
<connectionStrings>
<add name="myConnectionString" connectionString="server=localhost;database=myDb;uid=myUser;password=myPass;" />
</connectionStrings>
string connStr = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;