如何确保正确的DotNet Core包含在构建中? [英] How do I ensure correct DotNet Core gets included in the build?

查看:95
本文介绍了如何确保正确的DotNet Core包含在构建中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将.netcore 2.1.5 API部署到Windows 2012 Server R2

I am trying to deploy a .netcore 2.1.5 api to Windows 2012 Server R2

当前我发布的api网站在导航到它时出现以下错误

Currently my published api site gives the following error when I navigate to it

HTTP Error 502.5 - Process Failure

Common causes of this issue:
The application process failed to start
The application process started but then stopped
The application process started but failed to listen on the configured port

Troubleshooting steps:
Check the system event log for error messages
Enable logging the application process' stdout messages
Attach a debugger to the application process and inspect

For more information visit: https://go.microsoft.com/fwlink/?LinkID=808681

在事件日志中,我可以看到

In the event log I can see

Event 1000, IIS AspNetCore Module
Application 'MACHINE/WEBROOT/APPHOST/MYSITE.COM.AU/MYAPINAME' with physical root 'C:\WebSites\MYSITE.COM.AU\MyApps\MYAPINAME\' failed to start process
commandline '.\dotnet .\mydllname.dll', ErrorCode='0x80004005 : 80008083

来自此问题

我看到我可以加入

 <PublishWithAspNetCoreTargetManifest>False</PublishWithAspNetCoreTargetManifest>

在发布配置文件中如果要确保在主机计算机上安装了正确版本的DotNetCore.

In the publish profile If I want to ensure the correct version of DotNetCore gets installed on the host computer.

但是,如果我想使用Azure Devops,该如何设置?

But how do I set that up if I want to use Azure Devops?

我尝试在发布"任务中检查发布Web项目"

I tried checking Publish Web Projects in the Publish task

但是我得到一个错误

No web project was found in the repository. Web projects are identified by 
presence of either a web.config file or wwwroot folder in the directory.

找不到与指定模式匹配的项目文件.

Project file(s) matching the specified pattern were not found.

依赖项包括

Microsoft.AspNetCore.App 2.1.5  

但是我看不到部署了一个响应内核的dll.

but I don't see a coresponding dll deployed.

我尝试在计算机上安装dotnet-runtime-2.1.5,该软件是从以下位置下载的 安装站点

I tried installing dotnet-runtime-2.1.5 on the computer, downloaded from the installer site

[更新]

我注意到缺少日志文件夹,所以我手动创建了它

I noticed the logs folder was missing so I created it manually

[更新]

我添加了Eriawan建议的任务 YAML是

I added the task suggested by Eriawan The YAML is

    steps:
- task: DotNetCoreInstaller@0
  displayName: 'Use .NET Core sdk 2.1.5'
  inputs:
    version: 2.1.5

我进入日志

2018-10-29T08:29:05.4839748Z ##[section]Starting: Use .NET Core sdk 2.1.5
2018-10-29T08:29:05.4843909Z ==============================================================================
2018-10-29T08:29:05.4843981Z Task         : .NET Core Tool Installer
2018-10-29T08:29:05.4844041Z Description  : Acquires a specific version of .NET Core from internet or the tools cache and adds it to the PATH. Use this task to change the version of .NET Core used in subsequent tasks.
2018-10-29T08:29:05.4844089Z Version      : 0.1.16
2018-10-29T08:29:05.4844134Z Author       : Microsoft Corporation
2018-10-29T08:29:05.4844192Z Help         : [More Information](https://go.microsoft.com/fwlink/?linkid=853651)
2018-10-29T08:29:05.4844234Z ==============================================================================
2018-10-29T08:29:05.9812262Z Tool to install: .NET Core sdk version 2.1.5.
2018-10-29T08:29:05.9825645Z Checking if a cached copy exists for this version...
2018-10-29T08:29:05.9830151Z Cache does not contains this particular .NET Core. Will be downloaded and installed.
2018-10-29T08:29:05.9833458Z Detected platform (Primary): win-x64
2018-10-29T08:29:05.9833723Z Getting URL to download .NET Core sdk version: 2.1.5.
2018-10-29T08:29:06.5248134Z Could not fetch download information for version 2.1.5. Please check if the version specified is correct. You can refer the link for supported versions => https://github.com/dotnet/core/blob/master/release-notes/releases.json. Falling back to creating convention based URL.
2018-10-29T08:29:06.5481883Z [command]C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoLogo -Sta -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command "& 'D:\a\_tasks\DotNetCoreInstaller_b0ce7256-7898-45d3-9cb5-176b752bfea6\0.1.16\externals\install-dotnet.ps1' -Version 2.1.5 -DryRun"
2018-10-29T08:29:07.6386710Z dotnet-install: Payload URLs:
2018-10-29T08:29:07.6387117Z dotnet-install: Primary - https://dotnetcli.azureedge.net/dotnet/Sdk/2.1.5/dotnet-sdk-2.1.5-win-x64.zip
2018-10-29T08:29:07.6387245Z dotnet-install: Legacy - https://dotnetcli.azureedge.net/dotnet/Sdk/2.1.5/dotnet-dev-win-x64.2.1.5.zip
2018-10-29T08:29:07.6387445Z dotnet-install: Repeatable invocation: .\install-dotnet.ps1 -Version 2.1.5 -Channel LTS -Architecture x64 -InstallDir <auto>
2018-10-29T08:29:07.6451802Z Downloading: https://dotnetcli.azureedge.net/dotnet/Sdk/2.1.5/dotnet-sdk-2.1.5-win-x64.zip
2018-10-29T08:29:08.8792388Z ##[warning]Could not download installation package from this URL: https://dotnetcli.azureedge.net/dotnet/Sdk/2.1.5/dotnet-sdk-2.1.5-win-x64.zip Error: {}
2018-10-29T08:29:08.8807163Z Downloading: https://dotnetcli.azureedge.net/dotnet/Sdk/2.1.5/dotnet-dev-win-x64.2.1.5.zip
2018-10-29T08:29:09.5450400Z ##[warning]Could not download installation package from this URL: https://dotnetcli.azureedge.net/dotnet/Sdk/2.1.5/dotnet-dev-win-x64.2.1.5.zip Error: {}
2018-10-29T08:29:09.5453128Z ##[error]Failed to download package for installation
2018-10-29T08:29:09.5551776Z ##[section]Finishing: Use .NET Core sdk 2.1.5

设计师展示

csproj是

    <Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
           <ApplicationIcon />
    <OutputType>Exe</OutputType>
    <StartupObject />
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <DocumentationFile>bin\Debug\netcoreapp2.1\trackApi.xml</DocumentationFile>
    <DefineConstants>TRACE;DEBUG;NETCOREAPP2_1</DefineConstants>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
    <DocumentationFile>bin\Release\netcoreapp2.1\trackApi.xml</DocumentationFile>
  </PropertyGroup>

  <ItemGroup>
    <Folder Include="logs\" />
    <Folder Include="Views\Account\" />
    <Folder Include="wwwroot\" />
  </ItemGroup>

  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.3" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.5" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.5" />
    <PackageReference Include="Serilog.Extensions.Logging" Version="2.0.2" />
    <PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
    <PackageReference Include="Serilog.Sinks.RollingFile" Version="3.3.0" />
    <PackageReference Include="Swashbuckle.AspNetCore" Version="3.0.0" />
  </ItemGroup>

  <ItemGroup>
    <Content Update="appsettings.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
  </ItemGroup>

</Project>

[更新]

构建管道中的问题

[更新]

我使用YAML创建了新管道

I created a new pipeline using YAML

pool:
  vmImage: 'VS2017-Win2016'

variables:
  buildConfiguration: 'Debug'

steps:
- task: DotNetCoreInstaller@0
  displayName: 'Use .NET Core sdk 2.1.5'
  inputs:
    version: 2.1.5


- task: DotNetCoreCLI@2
  displayName: Restore
  inputs:
    command: restore

    projects: '**/Api*.csproj'

但是我仍然出现错误

018-10-29T09:36:13.7155347Z ##[section]Starting: Use .NET Core sdk 2.1.5
2018-10-29T09:36:13.7158688Z ==============================================================================
2018-10-29T09:36:13.7158742Z Task         : .NET Core Tool Installer
2018-10-29T09:36:13.7158774Z Description  : Acquires a specific version of .NET Core from internet or the tools cache and adds it to the PATH. Use this task to change the version of .NET Core used in subsequent tasks.
2018-10-29T09:36:13.7158842Z Version      : 0.1.16
2018-10-29T09:36:13.7158878Z Author       : Microsoft Corporation
2018-10-29T09:36:13.7158926Z Help         : [More Information](https://go.microsoft.com/fwlink/?linkid=853651)
2018-10-29T09:36:13.7158958Z ==============================================================================
2018-10-29T09:36:14.1220877Z Tool to install: .NET Core sdk version 2.1.5.
2018-10-29T09:36:14.1231419Z Checking if a cached copy exists for this version...
2018-10-29T09:36:14.1238258Z Cache does not contains this particular .NET Core. Will be downloaded and installed.
2018-10-29T09:36:14.1240864Z Detected platform (Primary): win-x64
2018-10-29T09:36:14.1240993Z Getting URL to download .NET Core sdk version: 2.1.5.
2018-10-29T09:36:14.5706519Z Could not fetch download information for version 2.1.5. Please check if the version specified is correct. You can refer the link for supported versions => https://github.com/dotnet/core/blob/master/release-notes/releases.json. Falling back to creating convention based URL.
2018-10-29T09:36:14.5957734Z [command]C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoLogo -Sta -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command "& 'D:\a\_tasks\DotNetCoreInstaller_b0ce7256-7898-45d3-9cb5-176b752bfea6\0.1.16\externals\install-dotnet.ps1' -Version 2.1.5 -DryRun"
2018-10-29T09:36:15.3109409Z dotnet-install: Payload URLs:
2018-10-29T09:36:15.3109790Z dotnet-install: Primary - https://dotnetcli.azureedge.net/dotnet/Sdk/2.1.5/dotnet-sdk-2.1.5-win-x64.zip
2018-10-29T09:36:15.3109942Z dotnet-install: Legacy - https://dotnetcli.azureedge.net/dotnet/Sdk/2.1.5/dotnet-dev-win-x64.2.1.5.zip
2018-10-29T09:36:15.3110089Z dotnet-install: Repeatable invocation: .\install-dotnet.ps1 -Version 2.1.5 -Channel LTS -Architecture x64 -InstallDir <auto>
2018-10-29T09:36:15.3188675Z Downloading: https://dotnetcli.azureedge.net/dotnet/Sdk/2.1.5/dotnet-sdk-2.1.5-win-x64.zip
2018-10-29T09:36:16.5236693Z ##[warning]Could not download installation package from this URL: https://dotnetcli.azureedge.net/dotnet/Sdk/2.1.5/dotnet-sdk-2.1.5-win-x64.zip Error: {}
2018-10-29T09:36:16.5256084Z Downloading: https://dotnetcli.azureedge.net/dotnet/Sdk/2.1.5/dotnet-dev-win-x64.2.1.5.zip
2018-10-29T09:36:17.2185860Z ##[warning]Could not download installation package from this URL: https://dotnetcli.azureedge.net/dotnet/Sdk/2.1.5/dotnet-dev-win-x64.2.1.5.zip Error: {}
2018-10-29T09:36:17.2189408Z ##[error]Failed to download package for installation
2018-10-29T09:36:17.2271136Z ##[section]Finishing: Use .NET Core sdk 2.1.5

网址 https ://dotnetcli.azureedge.net/dotnet/Sdk/2.1.5/dotnet-dev-win-x64.2.1.5.zip 显示错误

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<Error>
<Code>BlobNotFound</Code>
<Message>
The specified blob does not exist. RequestId:7447502f-301e-00a8-516d-6f7cde000000 Time:2018-10-29T09:57:58.4200303Z
</Message>
</Error>

[更新]

爱侣湾(Eriawan)有答案. 我需要使用YAML管道并在此处获取版本.

Eriawan has the answer. I needed to use a YAML pipeline and get the version here.

推荐答案

为了控制构建以使用特定版本的.NET Core运行时,您必须告诉构建代理安装要使用的.NET Core SDK,并且在构建代码之前指定要安装的SDK版本.

In order to control the build to use specific version of .NET Core runtime, you must tell the build agent to install the .NET Core SDK to use and also specify the SDK version to install before building your code.

如果在Azure DevOps Pipelines构建上使用YAML,则可以运行以下任务:DotNetCoreInstaller @ 0并将其版本设置为2.1.403.

If you use YAML on your Azure DevOps Pipelines build, you could run this task: DotNetCoreInstaller@0 and set the version of to 2.1.403 .

该任务必须在任何任务之前运行,最好是第一个要运行的任务.

The task must be run before any tasks, preferably the first task to run.

例如:

- task: DotNetCoreInstaller@0
  inputs:
    version: '2.1.403' 

如果您使用的是构建定义设计器,请添加" .NET Core工具安装程序"任务,然后从此处指定要使用的版本.

If you're using the build definition designer, add the ".NET Core Tool Installer" task and specify the version that you want to use from there.

请查阅MSFT文档上的.NET Core构建示例:

Please consult .NET Core build sample on MSFT docs:

更新1 :

好的,我已经看到您的构建错误.看起来.NET Core安装程序任务的2.1.403的.NET Core SDK的URL地址错误.

OK, I have seen your build error. Looks like the .NET Core installer task has wrong URL address for .NET Core SDK of 2.1.403.

您可以改用纯YAML.我将在.NET Core安装程序任务存储库中提交一个错误.同时,请使用完整的YAML.

You can use pure YAML instead. I will file a bug on the .NET Core installer task repo. In the meantime, please use a full YAML.

我已经有一个有效的YAML文件,该文件的示例可在我自己的存储库中找到.

I already have one working YAML file, a sample of this is available on my own repo.

例如:

https://github.com/RXCommunica/rx-azuredevops-rest/blob/master/azuredevopsrest-ci-vs2017.yml

更新2 :

我已经为您的YAML添加了评论. YAML上的.NET Core工具版本不正确.从原始版本更新/更改您的Yaml:

I have added comments for your YAML. The .NET Core tool version on your YAML is incorrect. Update/change your yaml from the original:

- task: DotNetCoreInstaller@0
  displayName: 'Use .NET Core sdk 2.1.5'
  inputs:
    version: 2.1.5

收件人:

- task: DotNetCoreInstaller@0
  displayName: 'Use .NET Core sdk 2.1.5'
  inputs:
    version: 2.1.403

这很重要,因为.NET Core运行时的版本不等于实际SDK工具版本的版本.

This is important, because version of .NET Core runtime is not equal to the version of the actual SDK tool version.

请参考此文档以获取工具版本和.NET Core 2.1的相关运行时列表:

Please consult this doc for the tool version and the related runtime list of .NET Core 2.1:

https://www.microsoft.com/net/download/dotnet -core/2.1

这篇关于如何确保正确的DotNet Core包含在构建中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆