Zev Spitz
Zev Spitz

Reputation: 15377

Using VS 2017 image, unable to build other projects in a solution which has one .NET Core 3 project

I have a solution with multiple projects, one of which targets .NET Core 3.

I need to build another project in the solution using both the VS 2019 image and the 2017 image. For the 2017 image, I don't need to build the .NET Core project; so I've disabled the build on that project using the VS Configuration Manager. However, the build still fails:

C:\Program Files\dotnet\sdk\2.2.108\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets(137,5): error NETSDK1045: The current .NET SDK does not support targeting .NET Core 3.0. Either target .NET Core 2.2 or lower, or use a version of the .NET SDK that supports .NET Core 3.0. [C:\projects\antlr4parsetreevisualizer_visualizerTestCore_visualizerTestCore.csproj]

because of that one project.

How can I tell AppVeyor to ignore the project in this instance?

I tried explicitly setting the build: project: element, but to no avail.

appveyor.yml

Upvotes: 2

Views: 257

Answers (2)

Zev Spitz
Zev Spitz

Reputation: 15377

Initially, I only had one .csproj file to build per configuration. Per build image, I passed the project to dotnet restore (in my case I also had to rework the matrix logic to depend on the appveyor_build_worker_image environment variable):

environment:
  matrix:

  - job_name: VS 2019 build
    appveyor_build_worker_image: Visual Studio 2019

  - job_name: VS 2017 build
    appveyor_build_worker_image: Visual Studio 2017

# ...

for:

# ...
- 
  matrix:
    only:
      - appveyor_build_worker_image: Visual Studio 2017

  configuration: ReleaseCI2017
  build:
    project: 2017\2017.csproj
  before_build:
    - cmd: dotnet restore 2017\2017.csproj

Once I did that, everything seems to work, even without downloading+installing .NET Core 3 in an install script.

appveyor.yml

Thread on AppVeyor support forum


But as it turned out, I needed to build two projects for each image. I've resolved this by using additional solution files to control which projects should be built under each image, instead of relying on the VS configuration manager.

I then pass each solution to the build: project element, and AppVeyor will only attempt to build the specific projects referenced by that solution.

appveyor.yml

AppVeyor log.

Upvotes: 0

Feodor Fitsner
Feodor Fitsner

Reputation: 2354

We are going to add .NET Core 3.0 to Visual Studio 2017 image in the next update (https://github.com/appveyor/ci/issues/3158). In the meantime, you can use the following script to install .NET Core 3.0 during the build:

install:
- ps: Invoke-WebRequest -Uri 'https://dot.net/v1/dotnet-install.ps1' -UseBasicParsing -OutFile "$env:temp\dotnet-install.ps1"
- ps: '& $env:temp\dotnet-install.ps1 -Architecture x64 -Version "3.0.100" -InstallDir "$env:ProgramFiles\dotnet"'

Regarding project exclusion - I believe you can disable project building for specific configuration in Visual Studio IDE ("Configuration manager..."). However, for .NET Core projects I'd recommend going away from building a solution to building particular projects with dotnet build .... Additionally, if you need to publish .NET Core app publishing solution won't work with dotnet publish command.

Upvotes: 3

Related Questions