外部化 appSettings 配置部分(使用 configSource)和 mstest 的冲突

发布于 2024-11-11 17:42:00 字数 1036 浏览 5 评论 0原文

我正在使用应用程序设置的外部化配置部分,以便每个开发人员能够拥有不同的配置部分,如下所示:

  <appSettings configSource="appsettings.config" />

当我针对此项目(它是一个 Web 应用程序)运行 mstest 时,它会像这样盲目地修改此部分:

  <appSettings configSource="appsettings.config">
    <add key="microsoft.visualstudio.teamsystems.backupinfo" value="1;web.config.backup.af6ed449-e04a-4a52-99d6-b8df0b133316" />
    <add key="microsoft.visualstudio.teamsystems.aspnetdevserver:/" value="56917;True;3448;1;-8588944684513929784" />
  </appSettings>

这显然是错误的,甚至根据模式。

它需要修改它的原因是指定有关它将要运行的 Cassini/dev 服务器的信息。我认为就是这样,它似乎没有修改文件中的任何其他部分(很难说,因为它也完全重新格式化文件)。

问题是,我必须做出哪些选择才能使其发挥作用?

到目前为止,我只提出了两个实用的,都是次优的

  1. 放弃 appsettings 的外部配置

  2. 从 Cassini 切换到 cassinidev - 然后我可以停止使用 [AspNet开发服务器()] 属性,即 结果 web.config 需要 修改

  3. 在VS中配置一些东西以防止它这样做。为什么会 它甚至关心自己的端口 卡西尼号正在做什么?我不能 找到任何配置设置。

  4. 等待 MS 修复此问题,这样 [AspNetDevelopmentServer()] 就会 使用外部化的 appSettings

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.teamsystems.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

  1. Abandon external config for appsettings

  2. 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

  3. 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.

  4. Wait for MS to fix this, so [AspNetDevelopmentServer()] would
    work with externalized appSettings

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

七颜 2024-11-18 17:42:00

有点延迟,所以我不知道这是否仍然与您相关......

但您可以使用 file= 属性configSource
即:

 <appSettings file="appsettings.config" /> 

虽然 configSource 期望只替换整个部分,但 file 会合并这些部分。因此,即使您添加了子元素,它仍然会添加外部文件中的附加元素。

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.

浊酒尽余欢 2024-11-18 17:42:00

我知道这是一个很晚的回复,但在 2018 年 7 月(使用 Visual Studio 2017)我仍然遇到了这个问题,但这里有更多信息,即使您使用 file 或 configSource 执行此操作,mstest 的问题是附加配置文件不会复制到您的 testresults 文件夹中。

我们发现 VSStudio 中的测试有所不同。
在那里您可以只使用类级别的部署属性。

对于在构建服务器上运行的测试,您需要执行以下步骤

首先将这些附加配置文件的属性设置为内容和内容。如果较新则复制

第二个添加 .testsettings 文件作为解决方案项,而不是每个项目!

<?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>

在测试中第三次引用此文件 => VS studio 的测试设置菜单

然后检查构建服务器上的 testresults 文件夹,它现在应该包含这两个文件

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文