question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot use locally built F# compiler within VS

See original GitHub issue

When building F# project using custom build F# compiler with custom keywords from Visual Studio error happens

FSC error FS2020: The assembly 'C:\d\github\dotnet\fsharp\artifacts/bin/fsc/Debug/net7.0/fsc.dll' is listed on the command line. Assemblies should be referenced using a command line flag such as '-r'. [C:\d\github\funsharp\ісх\ВеселШарп.Бібліотека.fsproj]

Even if build in VS does not works, what working

  • Build using dotnet build
  • Colorization within VS. New keywords correctly highlighted.

Repro steps

  1. Clone F# repo to C:\d\github\dotnet\fsharp
  2. Add aliases to existing F# keywords, For example add let => leet
  3. Create project which use these custom keywords.
  4. Add following properties in the Directory.Build.props of the F# project
<PropertyGroup>
  <FSharpRoot>C:\d\github\dotnet\fsharp\</FSharpRoot>
  <DotnetFscCompilerPath>$(FSharpRoot)artifacts/bin/fsc/Debug/net7.0/fsc.dll</DotnetFscCompilerPath>
  <Fsc_DotNET_DotnetFscCompilerPath>$(FSharpRoot)artifacts/bin/fsc/Debug/net7.0/fsc.dll</Fsc_DotNET_DotnetFscCompilerPath>
   <!-- these experiments and probably do not affect anything -->
  <FSharpPreferNetFrameworkTools>false</FSharpPreferNetFrameworkTools>
  <FSharpCompilerPath>$(FSharpRoot)artifacts/bin/fsc/Debug/net7.0/</FSharpCompilerPath>
</PropertyGroup>
  1. Open VisualFSharp.sln
  2. Run VisualFSharpDebug project
  3. Open F# project with custom keywords.
  4. Build project in the VS

In case if this is needed.

** Investigation ** From what I see DotnetFscCompilerPath passed to the Fsc task. And then FSC task produces

C:\d\github\dotnet\fsharp\artifacts\bin\fsc\Debug\net7.0\fsc.exe C:\d\github\dotnet\fsharp\artifacts/bin/fsc/Debug/net7.0/fsc.dll -o:obj\Debug\net7.0\ВеселШарп.Бібліотека.dll
-g
...
skipped
...

My understanding that proper call should be

dotnet.exe C:\d\github\dotnet\fsharp\artifacts/bin/fsc/Debug/net7.0/fsc.dll -o:obj\Debug\net7.0\ВеселШарп.Бібліотека.dll
-g
...
skipped
...

binlog.zip

Issue Analytics

  • State:open
  • Created 10 months ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
KevinRansomcommented, Dec 1, 2022

@kant2002 – okay I believe I have a much better 1 property solution. https://github.com/dotnet/fsharp/pull/14422

Once the PR is merged you will be able to do this:

  <PropertyGroup>
    <FSharpCompilerPath>C:\kevinransom\fsharp\artifacts\bin\fsc\Debug\net7.0\fsc.exe</FSharpCompilerPath>
  <PropertyGroup>
0reactions
vzarytovskiicommented, Mar 9, 2023

The following works for me in both VS and CLI:

<PropertyGroup>
  <DisableAutoSetFscCompilerPath>false</DisableAutoSetFscCompilerPath>
  <DotnetFscCompilerPath>$(MSBuildThisFileDirectory)../../../artifacts/bin/fsc/Debug/net7.0/fsc.dll</DotnetFscCompilerPath>
  <FSharpPreferNetFrameworkTools>False</FSharpPreferNetFrameworkTools>
  <FSharpPrefer64BitTools>True</FSharpPrefer64BitTools>
</PropertyGroup>

It may fail to work if shipped runtime in VS is a lower version than the compiler tfm.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot obtain value of local or argument as it is not ...
Go to Project Properties and under Build Make sure that the "Optimize Code" checkbox is unchecked. Also, set the "Debug Info" dropdown to...
Read more >
Cannot debug net6.0-macos Apps - Developer Community
When I hit debug, the following error is shown in the Terminal: Possible reasons for this include: * You misspelled a built-in dotnet...
Read more >
C/C++ extension FAQ
Frequently asked questions about the C/C++ extension in Visual Studio Code.
Read more >
Troubleshoot broken references - Visual Studio
To fix this problem, use one of the following methods: Delete the broken reference and then replace it by using the Add Reference...
Read more >
Troubleshoot Visual C++ Compiler or Visual C++ Linker
Open up a Visual Studio Command Prompt. · Create the LINK_REPRO environment variable pointing to an existing and empty directory, for example: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found