1

我在 ubuntu 14.04 vm 上运行了 dotnet core 1.0。我正在尝试为我的部署过程编写一个新贵脚本:

start on filesystem and started networking
respawn
chdir /home/dotnetuser/dotnetportal/
exec sudo /usr/bin/dotnet restore
exec sudo /usr/bin/dotnet run

运行此服务后,我验证日志并获得通常预期的内容(通过本地测试/开发 vm):

Hosting environment: Production
Content root path: /home/dotnetuser/dotnetportal
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.

我在我的域和 ssl 的 nginx 反向代理上有 localhost:5000:

server {
   # Enable HTTP/2
       listen 443 ssl; #http2;
       listen [::]:443 ssl; #http2;
       server_name portal.secret.com;

       # use the lets encrypt certificates
       ssl_certificate /etc/letsencrypt/live/portal.secret.com/fullchain.pem;
      ssl_certificate_key /etc/letsencrypt/live/portal.secret.com/privkey.pem;

      # include the SSL configuration from cipherli.st
      include snippets/ssl_params.conf;

     location / {

         proxy_pass http://localhost:5000;
         proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection keep-alive;
         proxy_set_header Host $host;
         proxy_cache_bypass $http_upgrade;
     }

}

但是,当我 curl https://portal.secret.com/再次验证日志时,我得到了一堆编译器错误。

请记住,直接从工作生产文件夹运行 dotnet run 时,我不会遇到任何错误,并且我能够访问该站点。

当我尝试从服务运行站点时的日志是:

an unhandled exception has occurred: Can not find compilation library location for package '    microsoft.aspnetcore.antiforgery'
 18 System.InvalidOperationException: Can not find compilation library location for package 'microsoft    .aspnetcore.antiforgery'
 19    at Microsoft.Extensions.DependencyModel.CompilationLibrary.ResolveReferencePaths()
 20    at System.Linq.Enumerable.<SelectManyIterator>d__157`2.MoveNext()
 21    at Microsoft.AspNetCore.Mvc.Razor.Compilation.MetadataReferenceFeatureProvider.PopulateFeature(    IEnumerable`1 parts, MetadataReferenceFeature feature ETC.....

是否有人对为什么仅在我启动服务而不是直接运行命令时才发生这种情况有任何见解?

更新:这是我的 Project.json

{
  "userSecretsId": "xxxxx",

  "dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.0.1",
      "type": "platform"
    },
    "System.Runtime.Loader": "4.0.0",
    "Microsoft.AspNetCore.Authentication.Cookies": "1.0.0",
    "Microsoft.AspNetCore.Diagnostics": "1.0.0",
    "Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.0",
    "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0",
    "Microsoft.AspNetCore.Mvc": "1.0.1",
    "Microsoft.AspNetCore.Razor.Tools": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    },
    "Microsoft.AspNetCore.Routing": "1.0.1",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
    "Microsoft.AspNetCore.StaticFiles": "1.0.0",
    "Microsoft.EntityFrameworkCore.Sqlite": "1.0.1",
    "Microsoft.EntityFrameworkCore.Tools": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    },
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.Extensions.Configuration.UserSecrets": "1.0.0",
    "Microsoft.Extensions.Logging": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Logging.Debug": "1.0.0",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0",
    "Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
      "version": "1.0.0-preview2-update1",
      "type": "build"
    },
    "Microsoft.VisualStudio.Web.CodeGenerators.Mvc": {
      "version": "1.0.0-preview2-update1",
      "type": "build"
    },
    "MongoDB.Driver" : "2.3.0"
  },

  "tools": {
    "Microsoft.AspNetCore.Razor.Tools": {
      "version": "1.0.0-preview2-final",
      "imports": "portable-net45+win8+dnxcore50"
    },
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": {
      "version": "1.0.0-preview2-final",
      "imports": "portable-net45+win8+dnxcore50"
    },
    "Microsoft.EntityFrameworkCore.Tools": {
      "version": "1.0.0-preview2-final",
      "imports": [
        "portable-net45+win8+dnxcore50",
        "portable-net45+win8"
      ]
    },
    "Microsoft.Extensions.SecretManager.Tools": {
      "version": "1.0.0-preview2-final",
      "imports": "portable-net45+win8+dnxcore50"
    },
    "Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
      "version": "1.0.0-preview2-final",
      "imports": [
        "portable-net45+win8+dnxcore50",
        "portable-net45+win8"
      ]
    }
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "dnxcore50",
        "portable-net45+win8"
      ]
    }
  },

  "buildOptions": {
    "debugType": "portable",
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "**/*.cshtml",
      "appsettings.json",
      "web.config"
    ]
  },

  "scripts": {
    "prepublish": [ "npm install", "bower install", "gulp clean", "gulp min" ],
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  },

  "tooling": {
    "defaultNamespace": "WebApplication"
  }
}
4

1 回答 1

0

我通过删除 /tmp/NuGetScratch 文件夹解决了这个问题,并明确告诉 linux 在哪个用户下运行应用程序。更新后的服务配置脚本是:

start on filesystem and started networking
respawn
 setuid dotnetuser
 env HOME=/home/dotnetuser
 exec rm -rf /tmp/NuGetScratch/
 chdir /home/dotnetuser/apps/dotnetportal
 exec dotnet restore
 exec dotnet run

问题是由于在我删除的目录(tmp/NuGetScratch)中找到的 nuget 锁定文件引起的文件权限问题,.net 没有编译。我想现在 .net 期望您以 root 身份运行 - 在这里找到:https ://github.com/dotnet/dotnet-docker/issues/78 (NuGet 缓存填充失败,因为 /tmp/NuGetScratch 归 root 所有或其他一些苏)

于 2016-10-25T01:47:23.367 回答