简体   繁体   中英

How can I add an app.config or web.config file in Visual Studio Web 2013?

This has been frustrating me for the past hour. My project is like

MySolution
    MyTestProject
      ClassThatTestsMyRepository.cs
    MyMVCProject
      App_Data
      App_Start
      Controllers
      .
      .

and the root of my problem is that my tests in the other project aren't working because they're trying to access a connection string that is in the MVC project itself. My plan was to add an app.config file and then reference the web.config in the MVC project. However, when I go to Add -> New Item there are no configuration files in Installed or Online.

screenshot

The only reason there's a web config in my MVC project is because it was built from a template that added it. Any ideas how I can add it to my test project if I can't add it through stupid VS Web 2013?

It is just an XML file called "web.config" placed at the root of your MVC project. Then you can just create a new text file and rename it. if the project is a console app or a test project, the name is App.config.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <connectionStrings>
    <add name="Default" connectionString="xxxx" />
  </connectionStrings>
</configuration>
  1. Right click your project and select Add New Item...
  2. Look for a template called Application Configuration File for local apps or it will be under Web Configuration File for ASP.NET projects.
  3. Choose the default name and press Add

添加 app.config

Relevant Microsoft Article

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