【问题标题】:Nancyfx Views not found when debugging ASP.NET Core 1.0 application调试 ASP.NET Core 1.0 应用程序时未找到 Nancyfx 视图
【发布时间】:2016-07-14 16:39:11
【问题描述】:

在调试模式下使用 Asp.net Core 1.0 解析 Nancyfx 视图时遇到问题。这是因为wwwroot 之类的文件夹不会在bin 文件夹中输出。我用谷歌搜索,但还没有找到将文件夹发送到bin/Debug 的方法。但是,当我发布并运行该应用程序时,视图得到了很好的解决。这是因为project.json 我可以配置要输出的文件夹。我知道我可以自定义ViewLocations,但如果我这样做是为了让它在debug 中工作,那么它在published 时将无法工作。

【问题讨论】:

    标签: nancy asp.net-core-1.0


    【解决方案1】:

    你有几个选择:

    1. 设置ContentRoot。以下代码使用项目目录作为视图的位置。

          public class Program
          {
              public static void Main(string[] args)
              {
                  var host = new WebHostBuilder()
                      .UseKestrel()
                      .UseContentRoot(Directory.GetCurrentDirectory())
                      .UseIISIntegration()
                      .UseStartup<Startup>()
                      .Build();
      
                  host.Run();
              }
          }
      
    2. 您可以为此目的使用project.json 中的copyToOutput 节点。

      例子:

      "buildOptions": {
        "copyToOutput": {
          "include": [
            "Areas",
            "Views",
            "wwwroot",
            "config.json",
            "web.config"
          ]
        }
      

    【讨论】:

    • 非常感谢。我已经在使用但不起作用的第一个选项。选项2 完成这项工作。
    • 现在使用 VS2017 中的 ASP.NET Web 应用程序 (.NET Core) 的默认模板,默认情况下再次没有 project.json。设置已迁移回项目文件。我能够在 View to Content | 上设置文件属性。如果较新,请复制。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多