Is it possible to replace individual values in an appSettings file on publish from Visual Studio - visual-studio

In my solution, there's a single appSettings.config file which is shared by a number of projects. It's referenced in the config files of those projects like this:
<appSettings file="appSettings.config" />
And that's all fine.
The individual config files also have Debug and Release configurations that I can use to control things like connection strings when I publish from local to live and that's also fine.
However, most of the key settings I want to change aren't in the project config files: they're in that appSettings file.
I could have two appSettings files in my solution and have the Debug > Release configuration change which one is referenced when the solution is published, but that seems a little clumsy - most of the settings are the same.
Right-clicking on the appSettings.config file doesn't give me an "add config transforms" option, so I'm guessing I can't have a Debug/Release transformation of that file itself.
Is there any other way to go about this other than replacing the whole file on publish?

Related

Running chutzpah on server and in Visual Studio using different projects

I'm having several projects containing my javascript sources and one project containing my javascript tests. Now I'm wondering how to set my references in the test files to make them work in Visual Studio and the automated integration build on server side. The challenge is that the file struture differs in both locations.
Locally (Visual Studio) there is the usual file structure:
project-a/
content/scripts/library-x.js
tests-project/
tests/library-x-test.js
I set a reference in library-test-js which looks like this and works fine in VS:
/// <reference path="../../project-a/content/scripts/library-x.js" />
On server side everything is copied to the build output folder what changes the file structure to look like this:
build-folder/library-x-test.js
build-folder/content/scripts/library-x.js
The reference in library-x-test.js doesn't work anymore there. Any ideas how to solve this issue?
You should use the chutzpah.json file to configure your file paths instead of the reference comments. The chutzpah.json file give you more control and lets you use wild cards. Path's in the chutzpah.json file are relative to the location of that file so you are sometimes able to make things work in both build and local as long as you place that file correctly.

Using Config Transformation with external files

I have a collection of web service and sites all installed on the same machine which share settings so I have put them in an external config file one folder above the application folders such as below.
<appSettings file="../common.config"/>
I see that with Config Transforms I can change individual values within this section had my settings been inside the appSettings block but is it possible to change the file attribute itself?
<appSettings file="../common_release.config"/>
or
The config transforms are actually applied by Visual Studio upon building a deployment package; so there is no *_release* or *_debug* version in the output.
Of course, you could use what ever files you want for external configuration.

How to prevent the copy of XML documentation files in a release mode build?

I have a Visual Studio 2010 project which references some third-party components. Their assemblies are accompanied by XML documentation files, which are useful for us (and only us) developers. And whenever the project is built (either in Debug or Release modes) these XML files are copied to the build directory.
I can't seem to find a setting or switch to disable the copy of those XML files to the build directory, either within Visual Studio or though MSBuild. A post-build script may be an option, but a smelly one. Any ideas? Thank you.
When you build a project the .xml/.pdb files are gathered through the ResolveAssemblyReference task. When ResolveAssemblyReference is called it is passed a list of file extensions for related files. That list of file extensions is captured in the MSBuild property AllowedReferenceRelatedFileExtensions. By default that list will contain ".pdb;.xml".
If you want to exclude all related reference files from being picked up then just override the value of the property to something which related files won't have extensions of. For example you can set AllowedReferenceRelatedFileExtensions to "-".
You can also customize the list of file which are returned by that. If you only want to find only .pdb files then you will need to pass in AllowedReferenceRelatedFileExtensions=".pdb". In that case any references which have .pdb file next to the .dll/.exe they will be copied as well. You can also use this to copy other related files which may not end in .pdb/.xml. For example if you have a referenced assembly named, MyAssembly.dll and in that same folder there exists MyAssembly.pdb and MyAssembly.foo If you set AllowedReferenceRelatedFileExtensions=".pdb;.foo" then both the .pdb and .foo file will be copied to the output directory.
Visual studio project file has the same format as any msbuild file. So you can manually add the condition into corresponding section to not copy your xml files if configuration name is 'Release'.
It should be changing
<ItemGroup>
to
<ItemGroup Condition="'$(CONFIG)'=='RELEASE'">
or something like this.
If the .xml/.pdb are marked as build-action "Content" (etc), you can change them to "None". You should also ensure they copy-to-build-output is false.
Are both of those set?
What is the problem with having the XML files get copied into the folder on release builds? It seems to me that this is fine and that the real problem is with the code that picks up files to place them in the installer. Picking up third party dlls from your own bin\release folder is not a good practice in my opinion. I'd have my installer pick up third party dlls from their own folder in my source tree.
The setting is in the Properties of the project in question, under the "Build" tab, uncheck "XML documentation file". It's also an MSBuild property called <DocumentationFile> under the applicable <PropertyGroup> for your build configuration in the .*proj file.

Is there a way to use one and only one settings file in stylecop?

Dinking around with stylecop settings files is getting annoying and messing with my repo structure. The repo is like this:
+ Trunk
+ src
- ProjectA
- ProjectB
- ...
+ lib
+ Icons
- ...
+ tools
+ NUnit
+ PartCover
- Settings.StyleCop
- ...
I would like all projects/solutions to use the settings file from trunk/tools and no others (preferable I'd like all settings file for only projects in this trunk to use that settings file, but system wide is acceptable.
I must be the only person who finds the way stylecop deals with settings files and merging settings files to be really annoying, or I just don't understand it properly.
You can create a parent settings file, which applies to all projects in subfolders of the folder where the settings file is located:
Sharing StyleCop Settings Across Projects
BUT: that means you can't put the settings file into the trunk/tools folder.
You have to put it directly into the trunk folder instead.
But in my opinion, that's no problem. I did this in my own project as well:
The StyleCop assemblies and the target file are in a subfolder named \Libs\StyleCop, only the settings file itself is in the root folder. I can live with that.
If you really don't want to put the settings file in the Trunk folder, then you do have one other option: Replace the settings file in the StyleCop install directory.
Definitely 'an option of last resort', it makes the project validate differently on another computer that hasn't replaced the default StyleCop settings file.
I wouldn't recommend going down this path unless absolutely necessary.
The best way to make all projects use the same settings is by having the settings file in the topmost directory shared by all projects, that's all there is to it.
Updated
See this guide (under, Analyzing All Projects) if you are using StyleCop.Analyzers nuget package.
If you are using StyleCop Installer (this is the old version of SyleCop), this is how it can be done:
I have several projects in my solution and I am using my Web project's StyleCop setting as the main (global) setting :
To do this, right click on any other project => StyleCop Settings
Choose: Merge with the following Settings file and choose the your main project's settings.StyleCop (in my case the Web project's setting):
That's it, now your main projects settings would be used for the other (child) project.
You can confirm this by opening your child project's StyleCop setting (note that it's hidden in VS):
And you can see that is referencing your global setting. You can repeat these step for all other required projects.

Visual Studio local project setting best-practices?

How do people commonly store local .settings files for their projects? For example, I have a solution for a web project in Mercurial. I have a data project containing my entities and repositories. My connection string is stored in Settings.settings and I'd like to have different sources depending on my location.
I was thinking I could simply move the file to Settings.settings.global and requiring anyone to change it when they clone my repo. Is there a better way of going about this? What are the best-practices for handling such things in Visual Studio?
One concern of mine with simply renaming the Settings.settings file containing my data source is that Visual Studio seems to automagically modify my app.config with the new values and I'm not sure how that will be handled if I force people to rename.
I'm not clear on whether your organization is using revision control or not, but generally speaking, the .settings file committed to your revision control server contains some generic settings (or more specifically, testing or production settings). Then, each developer simply checks out the project, modifies .settings freely to suit their local configuration, and never submits the changes back to the revision control server. Everybody's happy!
Not sure about .settings files, but for .config files and any other projects I'm using a file like app.config.sample which is included in the repository, along with a .cmd script which is creating the app.config file on run.
After cloning and running the .cmd script, any developer can customize the app.config as needed.
Off-topic: everyone I've asked advised me to keep the connection strings in app.config/web.config, but YMMV.
Some links:
ConnectionStrings Property
What is the best place to keep the Connection String

Resources