Azure / azure-functions-host

The host/runtime that powers Azure Functions
https://functions.azure.com
MIT License
1.94k stars 441 forks source link

Building version 4.0.3971 no longer works without patch #8252

Open RealGoodAnthony opened 2 years ago

RealGoodAnthony commented 2 years ago

When attempting to build version 4.0.3971 with build.sh, an error occurs:

/root/azure-functions-cli-source/azure-functions-core-tools-4.0.3971/test/Azure.Functions.Cli.Tests/Azure.Functions.Cli.Tests.csproj : warning NU1701: Package 'FSharp.Core 3.1.2.5' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework 'net6.0'. This package may not be fully compatible with your project. [/root/azure-functions-cli-source/azure-functions-core-tools-4.0.3971/Azure.Functions.Cli.sln]
/root/azure-functions-cli-source/azure-functions-core-tools-4.0.3971/test/Azure.Functions.Cli.Tests/Azure.Functions.Cli.Tests.csproj : warning NU1701: Package 'Suave 1.1.3' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework 'net6.0'. This package may not be fully compatible with your project. [/root/azure-functions-cli-source/azure-functions-core-tools-4.0.3971/Azure.Functions.Cli.sln]
/root/azure-functions-cli-source/azure-functions-core-tools-4.0.3971/test/Azure.Functions.Cli.Tests/Azure.Functions.Cli.Tests.csproj : warning NU1701: Package 'SuaveServerWrapper 0.0.3' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework 'net6.0'. This package may not be fully compatible with your project. [/root/azure-functions-cli-source/azure-functions-core-tools-4.0.3971/Azure.Functions.Cli.sln]
/root/azure-functions-cli-source/azure-functions-core-tools-4.0.3971/test/Azure.Functions.Cli.Tests/Azure.Functions.Cli.Tests.csproj : error NU1605: Detected package downgrade: Microsoft.ApplicationInsights from 2.20.0 to 2.18.0. Reference the package directly from the project to select a different version.  [/root/azure-functions-cli-source/azure-functions-core-tools-4.0.3971/Azure.Functions.Cli.sln]
/root/azure-functions-cli-source/azure-functions-core-tools-4.0.3971/test/Azure.Functions.Cli.Tests/Azure.Functions.Cli.Tests.csproj : error NU1605:  Azure.Functions.Cli.Tests -> Microsoft.Azure.Functions.CoreTools -> Microsoft.Azure.WebJobs.Script.WebHost 4.0.1 -> Microsoft.Azure.WebJobs.Script 4.0.1 -> Microsoft.Azure.WebJobs.Script.Abstractions 1.0.3-preview -> Microsoft.ApplicationInsights (>= 2.20.0)  [/root/azure-functions-cli-source/azure-functions-core-tools-4.0.3971/Azure.Functions.Cli.sln]
/root/azure-functions-cli-source/azure-functions-core-tools-4.0.3971/test/Azure.Functions.Cli.Tests/Azure.Functions.Cli.Tests.csproj : error NU1605:  Azure.Functions.Cli.Tests -> Microsoft.Azure.Functions.CoreTools -> Microsoft.ApplicationInsights (>= 2.18.0) [/root/azure-functions-cli-source/azure-functions-core-tools-4.0.3971/Azure.Functions.Cli.sln]
/root/azure-functions-cli-source/azure-functions-core-tools-4.0.3971/src/Azure.Functions.Cli/Azure.Functions.Cli.csproj : error NU1605: Detected package downgrade: Microsoft.ApplicationInsights from 2.20.0 to 2.18.0. Reference the package directly from the project to select a different version.  [/root/azure-functions-cli-source/azure-functions-core-tools-4.0.3971/Azure.Functions.Cli.sln]
/root/azure-functions-cli-source/azure-functions-core-tools-4.0.3971/src/Azure.Functions.Cli/Azure.Functions.Cli.csproj : error NU1605:  Microsoft.Azure.Functions.CoreTools -> Microsoft.Azure.WebJobs.Script.WebHost 4.0.1 -> Microsoft.Azure.WebJobs.Script 4.0.1 -> Microsoft.Azure.WebJobs.Script.Abstractions 1.0.3-preview -> Microsoft.ApplicationInsights (>= 2.20.0)  [/root/azure-functions-cli-source/azure-functions-core-tools-4.0.3971/Azure.Functions.Cli.sln]
/root/azure-functions-cli-source/azure-functions-core-tools-4.0.3971/src/Azure.Functions.Cli/Azure.Functions.Cli.csproj : error NU1605:  Microsoft.Azure.Functions.CoreTools -> Microsoft.ApplicationInsights (>= 2.18.0) [/root/azure-functions-cli-source/azure-functions-core-tools-4.0.3971/Azure.Functions.Cli.sln]
    3 Warning(s)
    2 Error(s)

It appears that the culprit is Microsoft.Azure.WebJobs.Script.WebHost, version 4.0.1, which has somehow been updated to use Microsoft.ApplicationInsights version 2.20.0 instead of 2.18.0. The major concern here is that this used to not be the case, and version 4.0.1 may have been overriden with a force-push to the NuGet package repository.

To me, this is very dangerous and concerning. Not only does it break this build, it goes against fundamental best practices that Nuget package versions should really be immutable.

Repro steps

Provide the steps required to reproduce the problem:

You may easily reproduce this issue with the following Dockerfile:

# syntax=docker/dockerfile:1
FROM mcr.microsoft.com/dotnet/sdk:6.0.100

# Install .NET Core 6.0 SDK
RUN apt-get update && \
    apt-get -y install wget unzip && \
    wget -q https://github.com/Azure/azure-functions-core-tools/archive/refs/tags/4.0.3971.zip -O azfunctions.zip && \
    unzip -d /root/azure-functions-cli-source azfunctions.zip

WORKDIR "/root/azure-functions-cli-source/azure-functions-core-tools-4.0.3971"

RUN dotnet build Azure.Functions.Cli.sln && \
    dotnet publish src/Azure.Functions.Cli/Azure.Functions.Cli.csproj --output /root/azure-functions-cli

Workaround

Create a patch file named 0001-app-insights-2.20.0.diff with the following contents:

From 62151049dca39ee44bd45eb1b511d7a14e8cb5d5 Mon Sep 17 00:00:00 2001
From: Anthony Iacono <anthonyiacono@gmail.com>
Date: Fri, 11 Mar 2022 12:25:43 -0500
Subject: [PATCH] Patch: Upgrade Microsoft.ApplicationInsights from 2.18.0 to
 2.20.0

---
 src/Azure.Functions.Cli/Azure.Functions.Cli.csproj | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/Azure.Functions.Cli/Azure.Functions.Cli.csproj b/src/Azure.Functions.Cli/Azure.Functions.Cli.csproj
index 426bdc3..32077c5 100644
--- a/src/Azure.Functions.Cli/Azure.Functions.Cli.csproj
+++ b/src/Azure.Functions.Cli/Azure.Functions.Cli.csproj
@@ -149,7 +149,7 @@
     <PackageReference Include="Colors.Net" Version="1.1.0" />
     <PackageReference Include="AccentedCommandLineParser" Version="2.0.0" />
     <PackageReference Include="DotNetZip" Version="1.13.3" />
-    <PackageReference Include="Microsoft.ApplicationInsights" Version="2.18.0" />
+    <PackageReference Include="Microsoft.ApplicationInsights" Version="2.20.0" />
     <PackageReference Include="Microsoft.AspNetCore.DataProtection" Version="2.2.0" />
     <PackageReference Include="Microsoft.Azure.DurableTask.AzureStorage.Internal" Version="1.4.0" />
     <PackageReference Include="Microsoft.Azure.WebJobs.Script.WebHost" Version="4.0.1" />
-- 
2.31.0

Update the Dockerfile:

# syntax=docker/dockerfile:1
FROM mcr.microsoft.com/dotnet/sdk:6.0.100

# Install .NET Core 6.0 SDK
RUN apt-get update && \
    apt-get -y install wget unzip && \
    wget -q https://github.com/Azure/azure-functions-core-tools/archive/refs/tags/4.0.3971.zip -O azfunctions.zip && \
    unzip -d /root/azure-functions-cli-source azfunctions.zip

WORKDIR "/root/azure-functions-cli-source/azure-functions-core-tools-4.0.3971"

COPY 0001-app-insights-2.20.0.diff .

RUN git apply 0001-app-insights-2.20.0.diff

RUN dotnet build Azure.Functions.Cli.sln && \
    dotnet publish src/Azure.Functions.Cli/Azure.Functions.Cli.csproj --output /root/azure-functions-cli
RealGoodAnthony commented 2 years ago

It just occurred to me that I may have posted this in the wrong area (although it also applies to this repository!)

Cross-posting to the appropriate repository: https://github.com/Azure/azure-functions-core-tools/issues/2980

v-bbalaiagar commented 2 years ago

Hi @pragnagopa , Could you please look into this issue

pragnagopa commented 2 years ago

Thanks for flagging this - will transfer to docker repo to triage

cc @TsuyoshiUshio @CooperLink for next steps

pragnagopa commented 2 years ago

@TsuyoshiUshio - can you take a look at this?

cc @CooperLink

RealGoodAnthony commented 2 years ago

@pragnagopa Thanks! By the way, this is not necessarily related to docker. You can reproduce the same exact issue by attempting to build on bare metal. I just provided a Dockerfile to simplify reproducing the issue.

pragnagopa commented 2 years ago

@fabiocav / @brettsam / @madelinegordon - can you please take a look? Looks like nuget package versions for the host were not updated?

RealGoodAnthony commented 2 years ago

Sorry to bug everyone, but I wanted to bump this @fabiocav @brettsam @madelinegordon @pragnagopa