Our Thoughts

  • Elegant Software Solutions

Porting a .NET web app from Visual Studio to MonoDevelop on Linux

Updated: May 29, 2020


In my last blog article, I talked about hosting .NET web apps on a Linux server. It takes a little bit of setup and deployment can be a bit more involved than it would be on a Windows server, but it’s a small learning curve that could save you a significant sum of money in hosting costs.

If you’re going to host your apps on Linux, you may also want to develop them in a Linux environment. That’s easy enough to do with a Linux based .NET IDE like Rider or MonoDevelop. But what if you have source code that has been written and maintained in Visual Studio that you would like to port to a Linux environment? In this article I’m going to walk through my experience of porting source code from Visual Studio in Windows to MonoDevelop in Linux.

I had an MVC web app with individual authentication that targeted .NET Framework 4.5. The very first and most obvious step was to just copy the entire solution over to the Linux machine then open it in MonoDevelop and try to compile it. The first error was related to the compiler settings in the web.config file. There are two entries in the “compilers” section of the web.config file that need to be changed.

Replace these lines:

<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />

<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />

With these:

<compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >

<providerOption name="CompilerVersion" value="v4.0" />

<providerOption name="WarnAsError" value="false" />

</compiler>

<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" warningLevel="4" type ="Microsoft.VisualBasic.VBCodeProvider, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >

<providerOption name="CompilerVersion" value="v4.0" />

<providerOption name="OptionInfer" value="true" />

<providerOption name="WarnAsError" value="false" />

</compiler>

The second error was related to Mono being unable to write debug information. The more recent projects I have ported did not have this problem, but it is an error that I saw with some early projects.

Removing this line from the .csproj file fixed that issue for me:

<Import Project="..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props')" />