ionide / proj-info

Parse and evaluate MsBuild project files
MIT License
64 stars 37 forks source link

Could not load file or assembly 'System.Runtime, Version=8.0.0.0 when multiple SDKs are present #197

Closed nojaf closed 1 year ago

nojaf commented 1 year ago

Describe the bug

fsdocs cannot crack my projects when multiple SDKs are present.

To Reproduce

Create an environment where the following SDKs are installed:

dotnet --list-sdks
7.0.203 [/home/nojaf/.dotnet/sdk]
7.0.305 [/home/nojaf/.dotnet/sdk]
7.0.400-preview.23311.1 [/home/nojaf/.dotnet/sdk]
8.0.100-preview.7.23376.3 [/home/nojaf/.dotnet/sdk]

(I don't know which SDK exactly causes the problem, this is what I had locally in WSL)

Steps to reproduce the behaviour:

Clone https://github.com/dawedawe/fantomas/tree/net8_lang_preview Run:

#!/bin/bash
dotnet tool restore
dotnet restore
dotnet build -c Release

SMV="$(pwd)/src/Fantomas/bin/Debug/net6.0/SemanticVersioning.dll"
dotnet fsdocs build --clean --properties Configuration=Release --fscoptions " -r:$SMV" --eval --strict --nonpublic

Expected behaviour Cracking should happen fine.

Screenshots

cracking projects...
  skipping project 'Fantomas.Core.fsproj' because an error occurred while cracking it: System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.

File name: 'System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
   at Ionide.ProjInfo.ProjectLoader.loadProject(String path, BinaryLogGeneration binaryLogs, FSharpList`1 globalProperties)
   at Ionide.ProjInfo.ProjectLoader.getProjectInfo(String path, FSharpList`1 globalProperties, BinaryLogGeneration binaryLogs, FSharpList`1 customProperties) in /_//src/Ionide.ProjInfo/Library.fs:line 842
   at fsdocs.Crack.crackProjectFileAndIncludeTargetFrameworks[a](a _slnDir, FSharpList`1 extraMsbuildProperties, String projectFile) in /home/runner/work/FSharp.Formatting/FSharp.Formatting/src/fsdocs-tool/ProjectCracker.fs:line 268
   at fsdocs.Crack.crackProjectFile[a](a slnDir, FSharpList`1 extraMsbuildProperties, String file) in /home/runner/work/FSharp.Formatting/FSharp.Formatting/src/fsdocs-tool/ProjectCracker.fs:line 348
   at fsdocs.Crack.projectInfos@451.Invoke(String p) in /home/runner/work/FSharp.Formatting/FSharp.Formatting/src/fsdocs-tool/ProjectCracker.fs:line 453
Project cracking failed and --strict is on, exiting

Environment (please complete the following information):

Additional context This problem doesn't occur when running this inside the docker image:

docker run -it --rm `
  -v ${PWD}:/app `
  -w /app `
  mcr.microsoft.com/dotnet/sdk:8.0-preview `
  pwsh

# dotnet --list-sdks      
# 8.0.100-preview.7.23376.3 [/usr/share/dotnet/sdk]

dotnet tool restore
dotnet restore
dotnet build -c Release

$SMV="$(pwd)/src/Fantomas/bin/Debug/net6.0/SemanticVersioning.dll"

dotnet fsdocs build --clean --properties Configuration=Release --fscoptions " -r:$SMV" --eval --strict --nonpublic

When only the preview SDK is present, this is not a problem.

I also ensured that https://github.com/ionide/proj-info/issues/195 is unrelated to this problem space.

nojaf commented 1 year ago

Turns out that while using the preview SDK it helps to use these environment variables:

$env:DOTNET_ROLL_FORWARD_TO_PRERELEASE = 1
$env:DOTNET_ROLL_FORWARD = LatestMajor

I was facing a runtime issue and nothing with the inner workings of proj-info.

nojaf commented 1 year ago

Thanks again @TheAngryByrd for pointing this out!