CSPROJ Pain: ASP.NET Core Razor Pages with Jetbrains Rider


I love Rider and they’ve generously provided me with a full license for my open source work. I can’t thank them enough.

The one downside to Rider is mono is used internally for many features instead of .NET Core. I know there are many reasons for this but I ran into a single issue with this:

(default target) (2) ->
(RazorCoreCompile target) -> 
  /usr/local/share/dotnet/sdk/2.2.103/Sdks/Microsoft.NET.Sdk.Razor/build/netstandard2.0/Microsoft.NET.Sdk.Razor.Compilation.targets(155,10): error MSB4064: The "SharedCompilationId" parameter is not supported by the "Csc" task. Verify the parameter exists on the task, and it is a settable public instance property. [/Users/adam/**********..csproj]
  /usr/local/share/dotnet/sdk/2.2.103/Sdks/Microsoft.NET.Sdk.Razor/build/netstandard2.0/Microsoft.NET.Sdk.Razor.Compilation.targets(107,5): error MSB4063: The "Csc" task could not be initialized with its input parameters.  [/Users/adam/**********.csproj]

The fix?

To fix this, I found that I needed to add a reference to Microsoft.Net.Compilers Sure, whatever. Little did I know this doesn’t work with the .NET Core compiler. So when building my Docker container I get this:

/root/.nuget/packages/microsoft.net.compilers/2.10.0/tools/Microsoft.CSharp.Core.targets(52,5): error MSB3883: Unexpected exception:  [/build/src/**********.csproj]
/root/.nuget/packages/microsoft.net.compilers/2.10.0/tools/Microsoft.CSharp.Core.targets(52,5): error : System.ComponentModel.Win32Exception (8): Exec format error [/build/src/**********.csproj]
/root/.nuget/packages/microsoft.net.compilers/2.10.0/tools/Microsoft.CSharp.Core.targets(52,5): error : at Interop.Sys.ForkAndExecProcess(String filename, String[] argv, String[] envp, String cwd, Boolean redirectStdin, Boolean redirectStdout, Boolean redirectStderr, Boolean setUser, UInt32 userId, UInt32 groupId, Int32& lpChildPid, Int32& stdinFd, Int32& stdoutFd, Int32& stderrFd, Boolean shouldThrow) [/build/src/**********.csproj]
/root/.nuget/packages/microsoft.net.compilers/2.10.0/tools/Microsoft.CSharp.Core.targets(52,5): error : at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo) [/build/src/**********.csproj]
/root/.nuget/packages/microsoft.net.compilers/2.10.0/tools/Microsoft.CSharp.Core.targets(52,5): error : at System.Diagnostics.Process.Start() [/build/src/**********.csproj]
/root/.nuget/packages/microsoft.net.compilers/2.10.0/tools/Microsoft.CSharp.Core.targets(52,5): error : at Microsoft.Build.Utilities.ToolTask.ExecuteTool(String pathToTool, String responseFileCommands, String commandLineCommands) [/build/src/**********.csproj]
/root/.nuget/packages/microsoft.net.compilers/2.10.0/tools/Microsoft.CSharp.Core.targets(52,5): error : at Microsoft.CodeAnalysis.BuildTasks.ManagedCompiler.ExecuteTool(String pathToTool, String responseFileCommands, String commandLineCommands) [/build/src/**********.csproj]

Great. Turns out Roslyn on for .NET Core has the right compiler but not for mono.


Now, I also really have enjoyed .NET Core since the early betas and really did reappreciate how they started over with the tooling. Now, I also appreciate to really drag everyone into .NET Core, they still needed msbuild…I guess.

Anyway, csproj, XML, msbuild…we still have to deal with this. I have to put a conditional package reference now!

Now, my complete csproj is this (with super awesome mono detection):

<Project Sdk="Microsoft.NET.Sdk.Web">


        <PackageReference Include="IdentityModel" Version="3.10.5" />
        <PackageReference Include="Microsoft.AspNetCore.App" />
        <PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
        <PackageReference Condition="$(CscToolPath.Contains('mono'))" Include="Microsoft.Net.Compilers" Version="2.10.0" />


Hope this helps someone else.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s