I am using externalized config section for appsettings, to be able to have different ones per developer, like so:
<appSettings configSource="appsettings.config" />
When I run mstest against this project (it's a web application), it blindly modifies this section like so:
<appSettings configSource="appsettings.config">
<add key="microsoft.visualstudio.teamsystems.backupinfo" value="1;web.config.backup.af6ed449-e04a-4a52-99d6-b8df0b133316" />
<add key="microsoft.visualstudio.teamsy开发者_开发百科stems.aspnetdevserver:/" value="56917;True;3448;1;-8588944684513929784" />
</appSettings>
Which is obviously wrong, even according to schema.
The reason it needs to modify this is to specify the information about Cassini/dev server that it's going to run. I think that's it, it doesn't seem to modify any other section in the file (very hard to tell since it also completely reformats the file).
Question is, what choices do I have to get this to work?
So far I only came up with two practical ones, both sub-optimal
Abandon external config for appsettings
Switch from Cassini to cassinidev - then I can stop using [AspNetDevelopmentServer()] attribute, which is the one that results in web.config needing to be modified
Configure something in VS to prevent it from doing this. Why does it even care which port its own cassini is working on? I couldn't find any config settings.
Wait for MS to fix this, so [AspNetDevelopmentServer()] would work with externalized appSettings
Bit of a delay, so I don't know if this is still relevant for you....
But you can use the file=
attribute of <appSettings>
instead of configSource
.
I.e:
<appSettings file="appsettings.config" />
While configSource
expects to just replace the entire section, file
merges the sections. So even if you have child elements added, it will still add the additional elements from the external file.
i know this is a very late response, but in july 2018 (with Visual Studio 2017) I still had this issue, but here is some more info, even if you do it with file or with configSource, the problem with mstest is that the additional config file will not be copied to your testresults folder.
We found out it was different for tests in VSStudio. There you can just use the deployment attribute on class level.
For our tests run on the build server, you will need to execute these steps
First set the properties of those additional config files to Content & Copy if newer
Second add a .testsettings file as a solution item, not per project !
<?xml version="1.0" encoding="UTF-8"?>
<TestSettings name="TestSettings"
id="350a1732-b798-4794-b711-15b44e8504e9"
xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
<Deployment>
<DeploymentItem filename="project1\file1.config" />
<DeploymentItem filename="project2\file2.config" />
</Deployment>
</TestSettings>
Third referenc to this file in the Test => Test Settings menu of VS studio
And then check the testresults folder on your build server, it should now contain those 2 files
精彩评论