【问题标题】:How can I add an app.config or web.config file in Visual Studio Web 2013?如何在 Visual Studio Web 2013 中添加 app.config 或 web.config 文件?
【发布时间】:2016-11-07 15:03:45
【问题描述】:

在过去的一个小时里,这让我很沮丧。我的项目就像

MySolution
    MyTestProject
      ClassThatTestsMyRepository.cs
    MyMVCProject
      App_Data
      App_Start
      Controllers
      .
      .

我的问题的根源是我在另一个项目中的测试无法正常工作,因为它们试图访问 MVC 项目本身中的连接字符串。我的计划是添加一个 app.config 文件,然后在 MVC 项目中引用 web.config。但是,当我转到 Add -> New Item 时,Installed 或 Online 中没有配置文件。

screenshot

我的 MVC 项目中存在 Web 配置的唯一原因是它是从添加它的模板构建的。如果我无法通过愚蠢的 VS Web 2013 添加它,有什么想法可以将它添加到我的测试项目中吗?

【问题讨论】:

    标签: c# .net asp.net-mvc visual-studio


    【解决方案1】:

    它只是一个名为“web.config”的 XML 文件,位于 MVC 项目的根目录中。 然后你可以创建一个新的文本文件并重命名它。 如果项目是控制台应用或测试项目,则名称为 App.config。

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <connectionStrings>
        <add name="Default" connectionString="xxxx" />
      </connectionStrings>
    </configuration>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-31
      • 1970-01-01
      • 2013-12-02
      • 1970-01-01
      相关资源
      最近更新 更多