Skip to content

Commit

Permalink
Handle Nuke .NET 9 preview issue (#6130)
Browse files Browse the repository at this point in the history
## Summary of changes

- Adds workaround for case where .NET 9 (preview) SDK is installed
lately.

## Reason for change

Fixes case where Nuke no longer works if you install the .NET 9  SDK

## Implementation details

Currently we have a global.json which enforces that we use the .NET
8.0.100 SDK for building _in general_. However, we have to use the .NET
7 SDK for running the Nuke project specifically when we're building the
Linux x64 _native_ components.

> This is because .NET 8 _doesn't_ support CentOS 7 and can't run there,
but we _have_ to use CentOS 7 currently for technical reasons.

We worked around this previously by specifically opting in to
major-version rollforward in the Nuke project. Unfortunately, Nuke
doesn't work out of the box with .NET 9 because of the [binary

formatter](https://learn.microsoft.com/en-gb/dotnet/standard/serialization/binaryformatter-security-guide)
removal. Consequently we have to make sure we _don't_ roll forward to
.NET 9 in that case.

The solution is pretty simple:
- Explicitly use .NET 8 _without_ roll forward in general
- Set an env var in the CentOS7 dockerfile `USE_NATIVE_SDK_VERSION=true`
which switches the Nuke project to build and run on .NET 7 explicitly

## Test coverage

Tested locally that it fixes the .NET 9 issue, this is the test for CI

## Other details

~The side-quest here was updating Nuke as it was quiet out of date. I
_thought_ it might be required, and it required fixing a _bunch_ of
warnings and breaking changes, so figured it would make sense to just do
the work here at the same time~ This ended up being a horrible pit of
errors so I abandoned it as it seems to be unnecessary.
  • Loading branch information
andrewlock authored Oct 14, 2024
1 parent a721f7b commit cabf0fd
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .azure-pipelines/ultimate-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ stages:
build: true
target: builder
baseImage: "universal"
useNativeSdkVersion: true
useNativeSdkVersion: false
command: "Clean BuildNativeLoader BuildNativeWrapper ExtractDebugInfoLinux"
retryCountForRunCommand: 1

Expand Down
4 changes: 2 additions & 2 deletions tracer/build/_build/_build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework Condition="$(USE_NATIVE_SDK_VERSION) == 'true'">net7.0</TargetFramework>
<TargetFramework Condition="$(OS.StartsWith('Windows')) AND '$(NUKE_NOTIFY)' != ''">$(TargetFramework)-windows10.0.19041</TargetFramework>
<DefineConstants Condition="$(OS.StartsWith('Windows')) AND '$(NUKE_NOTIFY)' != ''">$(DefineConstants);NUKE_NOTIFY</DefineConstants>
<RollForward>LatestMajor</RollForward>
<RootNamespace></RootNamespace>
<!-- NU* are workaround for Rider bug: https://youtrack.jetbrains.com/issue/RIDER-103207/Cannot-suppress-vulnerable-package-errors -->
<NoWarn>CS0649;CS0169;SA1652;NU1901;NU1902;NU1903;NU1904</NoWarn>
Expand Down
4 changes: 4 additions & 0 deletions tracer/build/_build/docker/centos7.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ ENV \

FROM base as builder

ENV USE_NATIVE_SDK_VERSION=true

# Copy the build project in and build it
COPY *.csproj *.props *.targets /build/
RUN dotnet restore /build
Expand All @@ -104,6 +106,8 @@ RUN if [ "$(uname -m)" = "x86_64" ]; \
&& rm dotnet-install.sh


ENV USE_NATIVE_SDK_VERSION=true

# Copy the build project in and build it
COPY *.csproj *.props *.targets /build/
RUN dotnet restore /build
Expand Down
1 change: 1 addition & 0 deletions tracer/build/_build/docker/universal.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ RUN ln -s `which clang-16` /usr/bin/clang && \

ENV \
DOTNET_ROLL_FORWARD_TO_PRERELEASE=1 \
USE_NATIVE_SDK_VERSION=true \
CXX=clang++ \
CC=clang

Expand Down

0 comments on commit cabf0fd

Please sign in to comment.