1
votes

So the situation is that I'm trying to get a build set up on bamboo that will build this solution that has many projects in it (it's a shared library solution), each of which is a nuget package. Bamboo is currently running on Ubuntu 16.04. The solution contains library projects (netstandard2.0) and tests (netcoreapp2.0). Each of the libraries targets both net461 and netstandard2.0 because they are used both in our newer .net core 2.0 applications as well as our 4.6.1 legacy platform.

The problem is that if I run dotnet build mysolution.sln then the cli attempts to build everything in net461 which obviously fails (linux machine). But if I run dotnet build mysolution.sln -f netstandard2.0then the tests fail to build because they are netcoreapp2.0.

The only thing I can think of is to write into the build script, a line that builds each individual project using the correct framework which seems a bit silly to me.

Luckily, all of the test projects are suffixed with .Tests so I feel like there's probably a way to do some find /path -regex 'match-csproj-where-not-tests' and so forth... voodoo to make this a bit less annoying. I'm wondering if someone out there might know something I don't about the dotnet cli that could help with this or even offer the regex solution.

TIA

1
Couldn't you just build the solution twice, once with netstandard and once with netcoreapp? - John Koerner
Problem is the failure code from the first build causes everything to fail - Sinaesthetic
You can use fallback to Mono or simply run a script to remove netNNN from your project files. - Lex Li

1 Answers

1
votes

While I'm waiting for better options, I came up with this:

#!/bin/bash

# build netstandard2.0
projects=($( find . -name '*.csproj' -print0 | xargs -0 ls | grep -P '(?![Tests])\w+\.csproj' ))
BUILDCODE=0
for proj in ${projects[@]}
do
    dotnet build $proj -f netstandard2.0
    BUILDCODE=$?
    if (($BUILDCODE != 0)); then
        echo "Failed to build $proj"
        break
    fi
done
(exit $BUILDCODE)

# build netcoreapp2.0
projects=($( find . -name '*.csproj' -print0 | xargs -0 ls | grep -P '\w+\.Tests\.csproj' ))
BUILDCODE=0
for proj in ${projects[@]}
do
    dotnet build $proj -f netcoreapp2.0
    BUILDCODE=$?
    if (($BUILDCODE != 0)); then
        echo "Failed to build $proj"
        break
    fi
done
(exit $BUILDCODE)

This searches for non Test suffixed projects and builds then as netstandard2.0 and those that are Test suffixed and builds them as netcoreapp2.0. I'd insert these as two different build tasks to ensure the exit codes cause failures and don't attempt to continue.

I'd likely have to do the same thing to run the xUnit tests since dotnet test solution.sln fails due to the library projects not containing tests ::eye_roll::