C#单元测试需要创建config文件才能实现webconfig里面的配置
来源:互联网 发布:在线支付系统源码 编辑:程序博客网 时间:2024/05/17 00:17
Problem: Unit tests fail when they depend upon a config file for another project in your solution. Proposed Solution #1: In each test project, create an App.config file with your AppSettings you'd normally put in Web.config or your main executable's config file. In your test project's properties pane, select Build Event and add this line to your post-build command line: copy /Y $(ProjectDir)app.config $(TargetPath).config Problem with solution #1: Not intuitive when you have a web.config format and transferring it to an app.config format. You also have 2 files to maintain when there is a change. Proposed Solution #2: Copy the config file into your test project output (bin) directory and rename it to YourTestAssembly.dll.config. Now you get all the config settings and you also get it copied automatically for you. Problem with solution #2: You still have to maintain 2 config files! Solution #3: Each time you build a Pre-Build event copies the master config file to the Test ouput dir and renames it using the .dll.config convention. On the deploy, you get an up to date config file but you only have to change it in one place – the source project. This is the full line in the Pre-Build event command line: copy $(SolutionDir)\Web16\web.config $(TargetDir)\$(TargetFileName).config Problem with this solution: The source project and config file name are hardcoded. You could use some kind of naming convention to make it work. it also assumes you have a 1-1 relationship between projects and test projects.
我用的第一种方法:在测试项目下加一个app.config文件,然后把webconfig里面的配置文件添加到app.config中。OK!搞定!
- C#单元测试需要创建config文件才能实现webconfig里面的配置
- 内核配置config失败需要的文件
- c# asp.net 修改webconfig文件 配置
- c# asp.net 修改webconfig文件 配置
- 应该是文件路径里面的"\",全都需要换成"\\"才能正常用的。
- asp.net 如何让虚拟目录里面的webconfig不继承主目录config
- asp.net 如何让虚拟目录里面的webconfig不继承主目录config
- 详解webconfig里面的configSections
- C#配置App.config文件
- C# 读取WebConfig配置信息
- webconfig的配置
- 虚拟目录webconfig的配置
- codeIgniter手动加载config里面的配置
- C#基本知识 -- App.config文件的配置与读取
- C#基本知识 -- App.config文件的配置与读取
- net中通过配置WebConfig设置文件上传的属性
- IIS配置 如何让虚拟目录里面的webconfig不继承网站的设置
- 读取webconfig里面的appSetting和connectionString
- iwpriv工具通过ioctl动态获取相应无线网卡驱动的private_args所有扩展参数
- 接口有什么用?
- mvc问题
- ubuntu12.10 chkconfig安装
- UILineBreakMode的各种情况
- C#单元测试需要创建config文件才能实现webconfig里面的配置
- Linux 命令记录
- 定义方法时不写public那么该方法的默认修饰符是什么?
- qtopia-2.2.0 无法启动 PC 仿真 --- 解决办法
- 双系统时windows覆盖linux主引导区MBR的解决办法
- 101个著名的管理学及心理学效应(1)
- android解析pdf文档
- XCode GDB常用命令使用
- iOS开发中使用宏定义提高开发效率