BundlerMinifier icon indicating copy to clipboard operation
BundlerMinifier copied to clipboard

Support .NET Core 3.1

Open danports opened this issue 5 years ago • 8 comments

dotnet bundle fails on the .NET 3.1 SDK Docker image (mcr.microsoft.com/dotnet/core/sdk:3.1) using BundlerMinifier.Core version 3.2.435:

  It was not possible to find any compatible framework version
  The framework 'Microsoft.NETCore.App', version '2.0.0' was not found.
     - The following frameworks were found:
         3.1.0 at [/usr/share/dotnet/shared/Microsoft.NETCore.App]

danports avatar Dec 26 '19 03:12 danports

Is anyone working on this or it can be picked up? Can I help? Have the same issue in the project I'm working on right now.

atsvetkov avatar Jan 09 '20 14:01 atsvetkov

Same problem, real blocker for us

Up.

turgayozgur avatar Jan 16 '20 06:01 turgayozgur

I agree this is annoying, but it shouldn't be too much of a blocker. Create your own sdk image and add both .net core 2.2 and 3.1, or whatever combo you need. Something like this will work:

RUN apt-get update &&\
    apt-get install wget -y &&\
    apt-get install apt-transport-https -y &&\
    wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb &&\
    dpkg -i packages-microsoft-prod.deb &&\
    apt-get update &&\
    apt-get install dotnet-sdk-2.1 -y &&\
    apt-get install dotnet-sdk-3.1 -y &&\
    apt-get remove --auto-remove apt-transport-https -y &&\
    apt-get remove --auto-remove wget -y &&\
    apt-get autoremove &&\
    apt-get clean

See the file I created here.

threax avatar Jan 18 '20 13:01 threax

Hit this today as well. This is straight hacky, but instead of building a custom sdk image I just made a Docker stage that does the bundling with netcoreapp2.1...

ARG BUILD_IMAGE=mcr.microsoft.com/dotnet/core/sdk:3.1.101-alpine
ARG BUNDLE_IMAGE=mcr.microsoft.com/dotnet/core/sdk:2.1-alpine
ARG RUNTIME_IMAGE=mcr.microsoft.com/dotnet/core/aspnet:3.1.1-alpine

# Copy csproj and restore
FROM ${BUILD_IMAGE} AS build
WORKDIR /app
COPY *.csproj .
RUN dotnet restore

# Copy everything else and bundle (must use 2.1 because of issue with BundlerMinifier.Core)
FROM ${BUNDLE_IMAGE} AS bundle
WORKDIR /app
COPY . .
# Rename current .csproj's to .csproj2
RUN for file in *.csproj; do mv "$file" "${file%.*}.csproj2"; done
# Write temporary bundle.csproj with only the BundlerMinifier tool
RUN echo "<Project Sdk=\"Microsoft.NET.Sdk.Web\"><PropertyGroup><TargetFramework>netcoreapp2.1</TargetFramework></PropertyGroup><ItemGroup><DotNetCliToolReference Include=\"BundlerMinifier.Core\" Version=\"3.2.435\" /></ItemGroup></Project>" > bundle.csproj
# Restore the tool, run bundle, and remove the temporary csproj
RUN dotnet restore && dotnet bundle && rm bundle.csproj
# Rename original .csproj's back
RUN for file in *.csproj2; do mv "$file" "${file%.*}.csproj"; done

# Pickup on original build image, copy from bundle image (includes bundled/minified files now), and publish app
FROM build AS build2
WORKDIR /app
COPY --from=bundle /app ./
RUN dotnet publish -c Release -o out

# Copy from final build and run
FROM ${RUNTIME_IMAGE}
WORKDIR /app
COPY --from=build2 /app/out ./
ENTRYPOINT ["dotnet", "myapp.dll"]

robertmiles3 avatar Feb 13 '20 08:02 robertmiles3

I'm rather upset the bundle output didn't even state it was running a dotnet bundle since I was overseeing a migration of a project from 2.2 -> .NET 5, and this was causing me issues for a good few hours until I figured out what was happened. My initial solution was also to just add a 2.2 build image to my Dockerfile so glad to see it's worked for someone else.

Interestingly I'm using the latest version which supposedly has added 3.1 support but was still getting this error...

KPatel91 avatar Feb 02 '21 22:02 KPatel91

Same problem. Have make migration from 3.1 to net 5 and I can't minify anymore. I have the 3.1.12 framework, but yet I cannot minify.

I am upset that I have to waste time because no version for .NET 5 exists.

I found this https://github.com/rwasef1830/BundlerMinifier, but I can't use and you can't add into your csproj as DotNetCliToolReference

Xarkam avatar Feb 22 '21 13:02 Xarkam

Still a problem in .NET 6. What is the recommended workaround or alternative?

lonix1 avatar May 04 '22 03:05 lonix1