简体   繁体   English

Visual Studio 2012测试项目正在从machine.config而非从app.config加载配置设置

[英]visual studio 2012 test project is loading configuration settings from machine.config but not from app.config

I am trapped in to a misterious issue. 我陷入了一个棘手的问题。 The visual studio 2012 test project, whenever I am tring to run it, is loading configuration settings from machine.config but not from app.config. 每当我尝试运行Visual Studio 2012测试项目时,它都会从machine.config中加载配置设置,而不是从app.config中加载配置设置。

What you are describing here is normal. 您在这里描述的是正常现象。 The reason for this the test runner is an external application that is ran by visual studio when you run the tests. 这样做的原因是测试运行程序是运行测试时Visual Studio运行的外部应用程序。 As such, the test runner has its own config file that you would have to modify to pull this off. 因此,测试运行器具有其自己的配置文件,您必须对其进行修改以实现此目的。 Conversely, the machine.config applies to every .net process that runs on your machine, so those settings will come in to the test project. 相反,machine.config适用于计算机上运行的每个.net进程,因此这些设置将进入测试项目。

The problem in Visual Studio 2012 itself. Visual Studio 2012本身的问题。 To run tests by default it doesn't use your bin folder, it deploys assemblies to system folder. 要默认运行测试,它不使用您的bin文件夹,而是将程序集部署到系统文件夹。

So, your app.config doesn't work in this case. 因此,您的app.config在这种情况下不起作用。 There are several solutions like copy your app.config to this folder on post build event or use .runsettings File. 有几种解决方案,例如在构建后事件中将 app.config复制到此文件夹或使用.runsettings文件。 But the simplest way is to update your Visual Studio. 但是最简单的方法是更新Visual Studio。

This issue was fixed in Visual Studio 2012 Update 4 and Visual Studio 2013. 此问题已在Visual Studio 2012 Update 4和Visual Studio 2013中修复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何确定是从app.config还是machine.config加载配置节或元素? - How to determine if a config section or element is loaded from app.config or machine.config? 将相同的密钥存储在Machine.config和App.config中 - Store same key in Machine.config and App.config 配置(app.config或web.config)在Visual Studio 2012中未显示智能感知 - configuration(app.config or web.config) is not showing intellisense in visual studio 2012 在C#中从Machine.Config访问客户配置设置子节点 - Accessing Customer Configuration Settings Child Nodes from Machine.Config in C# 来自“ app.config”的设置未在类库项目中获得 - Settings from “app.config” is not being gotton in class library project 将其他项目的设置添加到app.config - Add settings from another project to app.config 从类库中访问App.Config设置通过单元测试项目调用 - Access App.Config Settings from Class Library Called through Unit Test Project 通过从测试中读取App.config来简化测试配置 - Simplify test configuration by reading App.config from tests Azure App从machine.config获取连接字符串 - Azure App picking up connection string from machine.config 无法从app.Config读取设置 - Unable to read settings from app.Config
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM