简体   繁体   English

我应该如何在C#中的一个测试项目中链接多个项目App.config文件?

[英]How should I Link multiple projects App.config file in one Test Project in C#?

I want to link multiple projects App Config file into my Single Unit Test Project in DotNet framework in C#, As I wanted to access the different config files for different test methods. 我想将多个项目App Config文件链接到C#中DotNet框架中的单个单元测试项目,因为我想访问不同测试方法的不同配置文件。 Can anyone help me how should I make this done? 任何人都可以帮助我如何完成这项工作?

When I want to share files across multiple projects what I usually do is: 当我想在多个项目中共享文件时,我通常做的是:

  1. Add File to the root directory (where the solution is) 将文件添加到根目录(解决方案所在的位置)
  2. Right click the project you want to add the file to in Visual Studio 在Visual Studio中右键单击要添加文件的项目
  3. Hover over add 将鼠标悬停在添加上
  4. Click "Existing Item..." 点击“现有项目......”
  5. Navigate to the file 导航到该文件
  6. Click add as link 单击添加为链接

在此输入图像描述

This tells the project to reference something externally. 这告诉项目从外部引用一些东西。 In visual studio it will show as if it lives under the project like any other kind of file. 在visual studio中,它会像任何其他类型的文件一样显示它在项目下。

NB you may have to then change the properties of that linked file to make sure it is handled properly on build. 注意,您可能必须更改该链接文件的属性,以确保在构建时正确处理。 So you may or may not want it copied to the build directory for example. 因此,您可能会或可能不希望将其复制到构建目录中。

If you don't have visual studio then you can add this to the project file... 如果您没有visual studio,那么您可以将其添加到项目文件中......

  <ItemGroup>
     <AdditionalFiles Include="<PathToFile>\<Filename>" Link="<Filename>" />
  </ItemGroup>

This is an example from one of my projects 这是我的一个项目的一个例子

  <ItemGroup>
    <AdditionalFiles Include="..\..\stylecop.json" Link="stylecop.json" />
  </ItemGroup>

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM