在Visual Studio中使用2个项目和2个测试项目时,如何避免重复设置? [英] How to avoid duplicate settings when using 2 projects and 2 testing projects in Visual Studio?

查看:95
本文介绍了在Visual Studio中使用2个项目和2个测试项目时,如何避免重复设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

跟随我的上一个问题,现在我有2个项目:一个控制台项目和一个库项目.他们也有各自的单元测试项目.当我为使用库项目中方法的控制台项目运行测试并且库项目需要app.config设置时,该设置必须位于控制台测试项目的app.config中.我需要做些什么才能使其从库项目app.config中读取设置,因此我不必在多个app.config中重复设置?

Following my previous question, now I have 2 projects: one Console Project and a Library Project. They also have their respective unit test projects. When I run a test for the console project that uses a method from the library project and the library project needs an app.config setting, that setting must be in the console test project's app.config. What I have to do to make it read the setting from the library project app.config, so then I do not have to duplicate the setting across multiple app.config?

更新我不想在两个项目中使用相同的App.Config.我现在要做的是但现在不想做的是将所有库app.config设置复制到控制台项目设置中.

Update I don't want to use the same App.Config for both projects. What I am having to do now, but don't want to do anymore, is copying all the library app.config settings into the console project settings.

推荐答案

如果库项目是类库,则需要上下文来执行.VS不会读取类库的app.config文件,它会据我所知,它仅从执行上下文中读取app.config文件.该设置必须在控制台app.config中,因为这是执行的上下文.如果您正在运行单元测试并且它们是执行上下文,那么它们也将需要自己的app.config.

If the library project is a class library, then it needs a context to execute in. VS will not read the app.config file for a class library, it only reads the app.config file from the executing context, from what I can tell. The setting has to be in the console app.config because that is the context for execution. If you are running unit tests and they are the executing context then they will need their own app.config as well.

这篇关于在Visual Studio中使用2个项目和2个测试项目时,如何避免重复设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆