Visual Studio 2015 - Change Setting or Variable at time of Publish - variables

Is it possible to change a setting or variable when the application is published
or is there some sort of condition to run an IF THEN against?
for example, I want to change the way the log files are written when I publish and I often forget to make the change when I publish it

Web.Live.Config:
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<!--
In the example below, the "SetAttributes" transform will change the value of
"connectionString" to use "ReleaseSQLServer" only when the "Match" locator
finds an attribute "name" that has a value of "MyDB".
-->
<appSettings>
<add key="ClaimPackPath" value="C:\\inetpub\\wwwroot\\Application\\ClaimPacks\\" xdt:Locator="Match(key)" xdt:Transform="Replace" />
</appSettings>
</configuration>
Wg.Debug.Config:
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<!--
In the example below, the "SetAttributes" transform will change the value of
"connectionString" to use "ReleaseSQLServer" only when the "Match" locator
finds an attribute "name" that has a value of "MyDB".
-->
<appSettings>
<add key="ClaimPackPath" value="C:\\Debug\\wwwroot\\Application\\ClaimPacks\\" xdt:Locator="Match(key)" xdt:Transform="Replace" />
</appSettings>
</configuration>
Then in the application you can request the variable like so :
string filepath = ConfigurationManager.AppSettings["ClaimPackPath"];
And it will change for whatever publish profile you choose at time of publish :)

Related

C# : RedisCache Manager changing database number

I am using RedisCache for caching the data in c# application. so while configuring the RedisCache in app.config , we are setting the database='0', so if we change the database to other number between 1 to 15, its always taking 0 as defaultĀ  (ie) db0 as default.
Is there any way to change the Database number.
<redisCacheClient allowAdmin="false" ssl="false" connectTimeout="3000" poolSize = "5"
database="2" syncTimeout ="1000" abortOnConnectFail="true">
<serverEnumerationStrategy mode="All" targetRole="Any"
unreachableServerAction="IgnoreIfOtherAvailable" />
<hosts>
<add host="localhost" cachePort="6379" />
</hosts>
</redisCacheClient>
Thanks,
Raajesh K A

Cruise Control .NET Security

I am attempting to implement LDAP authentication, along with the required permissions.
<internalSecurity>
<cache type="inMemoryCache" duration="60" mode="sliding" />
<audit>
<xmlFileAudit location="D:\Logs\CCNet_Audit.xml"/>
</audit>
<auditReader type="xmlFileAuditReader" location="D:\Logs\CCNet_Audit.xml"/>
<users>
<ldapUser name="*username*" domain="*localdomain*"/>
</users>
<permissions>
<rolePermission name="Admin" forceBuild="Allow" sendMessage="Allow" startProject="Allow" changeProject="Allow" viewSecurity="Allow" modifySecurity="Allow" viewProject="Allow" viewConfiguration="Allow" >
<users>
<userName name="*username*"/>
</users>
</rolePermission>
</permissions>
Inside my project I have the following XML:
<project name="TestProject" description="TestProject" queue="Q7">
<security type="defaultProjectSecurity" defaultRight="Deny">
<permissions>
<rolePermission name="Admin" ref="Admin"/>
</permissions>
</security>
My log at (D:\Logs\CCNet_Audit.xml) is saying that I am "Denied"
<event><dateTime>2015-08-17T09:30:41.7973762-04:00</dateTime><user>*username*</user><type>Login</type><outcome>Deny</outcome></event>
and the project is unavailable within CC Tray.
My username is correct and I have the domain correct within the configuration (I just don't want to share it).
One thing I have noticed is that There seems to be a case issue within the username that Cruise Control is getting c-Joe.smith versus the english "normalization" of c-Joe.Smith . . . and yes I have tried it both ways.
Any help?
Try setting defaultRight="Allow" for your admin group.
<rolePermission name="Admin" defaultRight="Allow" forceBuild="Allow" sendMessage="Allow" startProject="Allow" changeProject="Allow" viewSecurity="Allow" modifySecurity="Allow" viewProject="Allow" viewConfiguration="Allow" >
<users>
<userName name="*username*"/>
</users>
</rolePermission>

Wix: How to remove comment in XML file

I have the following config file in my application:
<configuration>
<appSettings>
<!--Setting for user name-->
<add key="wcf:userName" value="wcfuser" />
<!--Setting for password-->
<add key="wcf:userPassword" value="abcdef" />
<!--Setting for is cloud application-->
<add key="IsCloudApplication" value="true" />
</appSettings>
<configuration>
I want remove this comment on the production server via Wix XmlConfig. I tried to use the following code:
<util:XmlConfig Id="RemoveWcfComments" File="[INSTALLFOLDER]Web.config" Action="delete" ElementPath="configuration/appSettings" VerifyPath="<!--Settings for user name-->" Node="element" On="install"/>
,but this is not working: exceptions no occurs, but the comment remains in the config file. Any ideas?
Thank in advance.
I'm not exactly sure but you can try this:
<util:XmlConfig
Id="RemoveWcfComments"
File="[INSTALLFOLDER]Web.config"
Action="delete"
ElementPath="//configuration/appSettings"
VerifyPath="//configuration/appSettings/comment()"
Node="value"
On="install"/>
As you can see ElementPath and VerifyPath are XPath-s, so they are invalid in your code. I'm not sure that Node="value" is right option, you could try Node="element" too.
Using Xpath the Comment() method will select all the the comments underneath AppSettings, if you have multiple comments but want to delete only one, then make use of the xpath below:
VerifyPath="//configuration/appSettings/comment()[.='Settings for user name and password']"
If there are multiple comments and you want to delete the first comment based on the order then you can make use of the below xpath as well:
VerifyPath="//configuration/appSettings/comment()[1]"

MSBuild, conditional NET runtime

I have a set of tools that need to be deployed on NET 3.5 or NET 4.0 depending on an MsBuild condition. At the moment we would like to change the project file of those utilities to handle this.
We are aware that we can do something like this:
<TargetFrameworkVersion Condition="">v3.5</TargetFrameworkVersion>
What is not clear for us is how can we specify different versions of NET depending on the condition. The condition property is an int that returns a number, between 1 and 4 and depending on that value we should target a different NET framework and of course change also this property in the app.config
<startup>
<supportedRuntime version="v2.0.50727"/>
</startup>
I want to know what is the right way of handling this type of problem.
You can give the condition like this one after other in your MSBuild file.
<TargetFrameworkVersion Condition="$(ConditionProperty) == '1'">v1.1.xxxx</TargetFrameworkVersion>
<TargetFrameworkVersion Condition="$(ConditionProperty) == '2'">v2.0.xxxx</TargetFrameworkVersion>
<TargetFrameworkVersion Condition="$(ConditionProperty) == '3'">v3.5.xxxx</TargetFrameworkVersion>
<TargetFrameworkVersion Condition="$(ConditionProperty) == '4'">v4.0.xxxx</TargetFrameworkVersion>
Accordingly you can write the code to change the value of
<startup>
<supportedRuntime version="v2.0.50727"/>
</startup>
in your app.cofig file as well by using the value of the variable $(TargetFrameworkVersion) using the code below:
<XmlUpdate XmlFileName="app.config"
XPath="//startup/supprtedRuntime[#version]"
Value="$(TargetFrameworkVersion)" />

XPath for web.config applicationSettings webdeploy parameters.xml file is not correct

I use webdeploy to deploy my web site project with a parameters.xml file I have been using a for a while. So far the parameters I've added are all element attributes and it all works well. But I am trying to get the xpath right to update an applicationSettings element value (not attributes) and am failing, badly, to work out if its my poor xpath skills to blame or a misunderstanding of the way the parameters file works.
When I do a deployment the field is not updated, it compiles fine and no errors\warnings during deployment. I want to be able to set this to True or False.
So I have following parameters field
<parameter name="ShowExceptionCallStackOnErrorView" description="Display a call stack on the UI Error view - true for debug only." defaultValue="False" tags="">
<parameterEntry kind="XmlFile" scope="\\web.config$" match="/configuration/applicationSettings/abc.123.Properties.Settings/setting[#name='ShowExceptionCallStackOnErrorView']/value" />
</parameter>
trying to match to the following application settings section
<configuration>
<applicationSettings>
<abc.123.Properties.Settings>
<setting name="ShowExceptionCallStackOnErrorView" serializeAs="String">
<value>True</value>
Any help would be much appreciated!
It's not giving you an error because it is simply not finding a match to replace. You need to add /text() to the end of your match tag if you want it to replace the contents of the value tag. As follows...
<parameter name="ShowExceptionCallStackOnErrorView" description="Display a call stack on the UI Error view - true for debug only." defaultValue="False" tags="">
<parameterEntry kind="XmlFile" scope="\\web.config$" match="/configuration/applicationSettings/abc.123.Properties.Settings/setting[#name='ShowExceptionCallStackOnErrorView']/value/text()" />
</parameter>