简体   繁体   中英

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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