1

I have a solution with target framework of 4.7.1. I have locally installed dotnet core sdks and able to issue build, publish commands.

My project file looks like this, with many references to dotnet core dlls

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

  <PropertyGroup>
    <TargetFramework>net471</TargetFramework>
    <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
    <TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
    <IsPackable>false</IsPackable>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Autofac.Extensions.DependencyInjection" Version="4.3.0" />
    <PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.4.1" />
    <PackageReference Include="Microsoft.AspNetCore" Version="2.1.3" />
    <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="2.1.2" />
    <PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="2.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.HttpsPolicy" Version="2.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="2.1.3" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.1.2" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="2.3.0" />
    <PackageReference Include="Microsoft.AspNetCore.Session" Version="2.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="2.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.1.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.1.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.1.0">

I have errors in Azure DevOps yaml while trying to use a specific .net sdk to build this solution.

    - task: UseDotNet@2
  inputs:
    packageType: 'sdk'
    version: '2.x'
- task: DotNetCoreCLI@2
  inputs:
    command: 'build'
    workingDirectory: '$(solution)'

The error reads There was an error when attempting to execute the process 'C:\hostedtoolcache\windows\dotnet\dotnet.exe'. This may indicate the process failed to start. Error: spawn C:\hostedtoolcache\windows\dotnet\dotnet.exe

More importantly, I am not sure which dotnet core version should I use to build this project?

Locally, I have dotnet 5 sdk and able to publish successfully using dotnet publish commands. What commands should I ideally use in DevOps to build a net471 project?

Thanks, AK

KeenUser
  • 5,305
  • 14
  • 41
  • 62
  • 1
    .NET Core != .NET Framework. So you can't use .NET Core tools to build a .NET Framework project. Despite the name similarity, you should treat them as if they are completely separate systems (which they basically are) - what you're trying to do will work just as badly if it was a Java project you were trying to compile. Pretty sure there are tutorials already which would show you how to build a Framework project in DevOps if you google carefully. – ADyson Dec 21 '20 at 11:12
  • Starting with Net 4.7.2 you can target a project to Net or Core. – jdweng Dec 21 '20 at 11:21

1 Answers1

8

.NET Core is different as compared to .NET Framework.

Moreover, if you want to create a pipeline for your .NET Framework project, you cannot use .NET Core tasks. Your YAML file of Pipeline should look like below:

# ASP.NET
# Build and test ASP.NET projects.
# Add steps that publish symbols, save build artifacts, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/apps/aspnet/build-aspnet-4

trigger:
- master

pool:
  vmImage: 'VS2017-Win2016'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:
- task: NuGetToolInstaller@0

- task: NuGetCommand@2
  inputs:
    restoreSolution: '$(solution)'

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: VSTest@2
  inputs:
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: PublishBuildArtifacts@1
  displayName: 'Publish artifacts'
  inputs:
    PathtoPublish: $(build.artifactstagingdirectory)
    ArtifactName: 'PublishBuildArtifacts'

    

Refer a step-by-step tutorial for this here.

Harshita Singh
  • 4,590
  • 1
  • 10
  • 13
  • thank you for this , I started with this, but since I was locally able to use dotnet publish command, I wonderered if that was possible. At the end of task: VSBuild@1, is it equivalent to Publish from Visual Studio? – KeenUser Dec 21 '20 at 11:40
  • No, it is equivalent to `Build` in Visual Studio. It creates artifacts after it is complete on the agent machine. – Harshita Singh Jan 04 '21 at 07:32