VS 2015 Release Management Tokenize XPath/Regular expressions not working - tfs

I'm trying to set up a token replacement for my config files. I have the source filename set to:
$(System.DefaultWorkingDirectory)/TFS Web Build 1.0/Corporate Art\app.RM.config
(Here, the RM file is the tokenized config file using token)
The destination filename is set to the true name of the config file:
Company.Client.Corporate.exe.config
I have the json file on the build server at:
\0111-03-0555-01\c$\BuildFiles\Transforms.json
The transforms.json file has the following data in it:
[
{
"CompanyTestDomain": {"QA4"},
"Environment": {"QA4.com"},
"CheckForContext": {"true"},
"ServiceTierAppHost": {"0111-06-0555-00-01.Company.com"},
"ServiceTierCsHost": {"0111-03-0444-00.Company.com"},
"ReportServer": {"0777-02-0111-00-01.Company.com"},
"ReportID": {"systemID"},
"ReportDomain": {"Corp"},
"ReportPWord": {"Password"}
}
]
The powershell is executed C:\Users\Public\Downloads\agent\tasks\Tokenizer\2.0.2\tokenize.ps1
The next line is grey as opposed to black which all the other information is:
##[debug]Performing the operation "Copy File" on target "Item:
C:\Agent_work\85c7a0d97\TFS Web Build 1.0\CorporateArt\app.RM.config
Destination: C:\Users\Public\Downloads\agent\tasks\Tokenizer\2.0.2\Isagenix.Clients.CorporateBackOffice.exe.config.tmp".
after which, I start getting messages that it's Updating token 'CompanyTestDomain'
No value found for token 'CompanyTestDomain'
So, can someone help me figure out what i'm doing wrong?

The content of configuration file should be like this (Contains a section ConfigChanges)
For example:
Sources file content:
<?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.6.2" />
</startup>
</configuration>
Configuration file content:
{
"Default Environment": {
"CustomVariables": {
"Token2": "value_from_custom2",
"Token3": "value_from_custom3"
},
"ConfigChanges": [
{
"KeyName": "/configuration/appSettings/add[#key='TestKey1']",
"Attribute": "value",
"Value": "value_from_xpath"
}
]
}
}
Variable in release definition: Token4 t4
Result:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="TestKey1" value="value_from_xpath" />
<add key="TestKey2" value="value_from_custom2" />
<add key="TestKey3" value="value_from_custom3" />
<add key="TestKey4" value="t4" />
</appSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" />
</startup>
</configuration>
More information, you can check these articles (1, 2).

Related

Configuring Serilog to write to Slack via app.config

I've created an application that I want to get logging to Slack for a particular purpose. I've already confirmed that it is working logging to a RollingFile and to Seq. I've added in serilog.sinks.slackclient and the application runs, and logs, but nothing shows up in my Slack channel.
Can someone verify whether there is an issue with my config?
from app.config (obviously xxx, yyy, zzz are substituded for key values.):
<add key="serilog:minimum-level" value="Debug" />
<!--<add key="serilog:using:RollingFile" value="Serilog.Sinks.RollingFile" />-->
<add key="serilog:using:Slack" value="Serilog.Sinks.Slack" />
<add key="serilog:write-to:Slack" value="https://hooks.slack.com/services/xxx/yyy/zzz" />
<add key="serilog:write-to:Seq.serverUrl" value="http://localhost:5341/" />
<add key="serilog:write-to:RollingFile.pathFormat" value="C:\Logs\Serilog\Test-{Date}.txt" />
<add key="serilog:write-to:RollingFile.retainedFileCountLimit" value="10" />
The parameter name webhookUrl is missing out of the write-to directive:
<add key="serilog:write-to:Slack.webhookUrl"
value="https://hooks.slack.com/services/xxx/yyy/zzz" />

Serilog - AppSettings MinLevel not working

I am trying to wire up my sinks and it seems for my rolling file sink my debug messages are not being logged (only info and above). Is my configuration wrong?
<!-- Serilog Configuration -->
<add key="serilog:using:Email" value="Serilog.Sinks.Email" />
<!-- Configure Serilog Email Sink -->
<add key="serilog:write-to:Email" />
<add key="serilog:write-to:Email.mailServer" value="***" />
<add key="serilog:write-to:Email.toEmail" value="***" />
<add key="serilog:write-to:Email.fromEmail" value="***" />
<add key="serilog:write-to:Email.mailSubject" value="Comply360 Portal Endpoint (DEV)" />
<add key="serilog:write-to:Email.restrictedToMinimumLevel" value="Warning" />
<add key="serilog:write-to:Email.outputTemplate" value="{Timestamp:HH:mm:ss} [{Level}] [{SourceContext}] [{CorrelationId}] {Message}{NewLine}{Exception}" />
<!-- Configure Serilog RollingFile Sink -->
<add key="serilog:write-to:RollingFile" />
<add key="serilog:write-to:RollingFile.restrictedToMinimumLevel" value="Debug" />
<add key="serilog:write-to:RollingFile.pathFormat" value="C:\Logs\comply360-portal-{Date}.txt" />
<add key="serilog:write-to:RollingFile.outputTemplate" value="{Timestamp:HH:mm:ss} [{Level}] [{SourceContext}] [{CorrelationId}] {Message}{NewLine}{Exception}" />
There is nothing "wrong" with your RollingFile sink config per se - it will only log messages with log level Debug or above (i.e. it will not log Verbose messages) as you intended.
However, the minimum log level for Serilog in general is Information, so it doesn't even send to your sink.
You need to change Serilog's default minimum level to at least Debug, in your case:
<add key="serilog:minimum-level" value="Debug" />
Your final config should look like this:
<add key="serilog:minimum-level" value="Debug" />
<add key="serilog:write-to:RollingFile" />
<add key="serilog:write-to:RollingFile.restrictedToMinimumLevel" value="Debug" />
<add key="serilog:write-to:RollingFile.pathFormat" value="C:\Logs\log-portal-{Date}.txt" />
<add key="serilog:write-to:RollingFile.outputTemplate" value="{Timestamp:HH:mm:ss} [{Level}] [{SourceContext}] [{CorrelationId}] {Message}{NewLine}{Exception}" />
Of course, if you later decide to add any sink that logs Verbose messages and above, you'll need to change the minimum-level to Verbose too.
i.e. serilog:minimum-level should always be the lowest level from all of your sinks.

IIS default document not found

After I manually set up a virtual directory in IIS on an Umbraco website (that uses MVC), I get a 404 not found error when attempting to browse the URL:
mydomain/myvirtualdirectory/
I have the file index.html in the physical directory that the virtual directory points to and I configured IIS to look for index.html as the default document for the virtual directory.
Turns out that Umbraco was 'intefering'. I needed to add a web.config under the physical folder that the virtual directory points to (the 'ExtensionlessUrlHandler' bit is switching off functionality applied by Umbraco, which was the main problem). This can all be generated via the UI in IIS, or can just be added manually.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<defaultDocument>
<files>
<clear />
<add value="index.html" />
<add value="Default.htm" />
<add value="Default.asp" />
<add value="index.htm" />
<add value="iisstart.htm" />
<add value="default.aspx" />
</files>
</defaultDocument>
<handlers>
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
</handlers>
</system.webServer>
</configuration>

Transform appSettings from external file after merge

What I'm trying to do is transform one of appSettings which is in external file:
Here is external.config
<?xml version="1.0"?>
<appSettings>
<add key="SomeKey" value="some value" />
</appSettings>
Web.config
<?xml version="1.0"?>
<configuration>
<appSettings file="..\..\external.config">
<add key="SomeKey1" value="some value 1" />
</appSettings>
</configuration>
Web.Debug.config
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<appSettings>
<add key="SomeKey" value="some changed value"xdt:Transform="SetAttributes" xdt:Locator="Match(key)"/>
</appSettings>
</configuration>
After build in proper configuration which in my example is Debug there's only this:
<?xml version="1.0"?>
<configuration>
<appSettings file="..\..\external.config">
<add key="SomeKey1" value="some value 1" />
</appSettings>
</configuration>
but it should be:
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<appSettings>
<add key="SomeKey1" value="some value 1" />
<add key="SomeKey" value="some changed value"/>
</appSettings>
</configuration>
I tryed to make shared appSettings by 2 or more different project 1-st is WCF Service second ASP.NET MVC 4 Application
Edited:
I've tryed to move this file attribute to Web.Debug.config but it's as well doesn't work.
The question is:
How can i accomplish such thing?Is it even possible?
Interesting. I have the same issue like yours. So now here is a workaround for your reference.
Please open project file - XXX.csproj
for example, ISWB.Test.Unit.csproj
add below section like this
<!-- Rock Add here, 2015.03.19 enable the external config transformation -->
<Target Name="BeforeCompile" Condition="Exists('ISWB.$(Configuration).config')">
<!--Generate transformed app config in the intermediate directory-->
<TransformXml Source="ISWB.config" Destination="$(IntermediateOutputPath)ISWB.config" Transform="ISWB.$(Configuration).config" />
<!--Force build process to use the transformed configuration file from now on.-->
<ItemGroup>
<AppConfigWithTargetPath Remove="ISWB.config" />
<AppConfigWithTargetPath Include="$(IntermediateOutputPath)ISWB.config">
<TargetPath>ISWB.config</TargetPath>
</AppConfigWithTargetPath>
</ItemGroup>
</Target>
<Target Name="AfterCompile" Condition="Exists('app.$(Configuration).config')">
<!--Generate transformed app config in the intermediate directory-->
<TransformXml Source="app.config" Destination="$(IntermediateOutputPath)$(TargetFileName).config" Transform="app.$(Configuration).config" />
<!--Force build process to use the transformed configuration file from now on.-->
<ItemGroup>
<AppConfigWithTargetPath Remove="app.config" />
<AppConfigWithTargetPath Include="$(IntermediateOutputPath)$(TargetFileName).config">
<TargetPath>$(TargetFileName).config</TargetPath>
</AppConfigWithTargetPath>
</ItemGroup>
</Target>
Please notice the added section, you have to add it into cs project file in a TEXT editor manually.
Please replace ISWB with yours. And then save it.
it should work well.
Enjoy it!

Web.config transformations in ASP.NET MVC 2 and extra Web.config files

i'm trying to use the Web.config transformations in my ASP.NET MVC 2 project running on .NET 4. However, I am having a problem:
// Root Web.config
<add name="MyDB" connectionString="default...default" />
// Root Web.Debug.config
<add name="MyDB" connectionString="debug...debug" xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />
// Root Web.Release.config
<add name="MyDB" connectionString="release... release" xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />
I keep getting this error:
Warning No element in the source document matches '/configuration/add[#name='MyDB']' C:\filePath\Web.Release.config
I narrowed this down to the Web.Config file inside the Views folder. If I give it a connectionString, such as the one in the root Web.config file, than all is well, but that means I have to maintain two Web.config files. Is there any solution to this? Am I doing something wrong?
Not sure why web.config in the views folder is being implicated but from the error you're getting it sounds like you've got a mismatch between the element in web.config and the transform config files.
In web.config, assuming <add /> is a child of <connectionStrings /> you'd do:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
...
<connectionStrings>
<add name="SomeName" providerName="System.Data.SqlClient" connectionString="SomeConnectionString" />
</connectionStrings>
...
</configuration>
and in web.debug.config
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
...
<connectionStrings>
<add xdt:Locator="Match(name)" xdt:Transform="SetAttributes(connectionString)" name="SomeName" connectionString="SomeOtherConnectionString" />
</connectionStrings>
...
</configuration>
As I already said:
Don't forget to manually copy all the other attributes of "configuration" from the original "web.config", as it seems that VS2012 doesn't do it automatically, so there will be no match...

Resources