I cant remove roslyn from published ASP .NET Website using various methods - asp.net

I am attempting to publish a Webforms website and noticed that the bin folder contains the 'roslyn' subfolder.
After researching it appears that removing 2 nugget packages would resolve the issue.
The problem is that removing the packages doesn't work.
I tried the Nuget package manager console:
uninstall-package Microsoft.CodeDom.Providers.DotNetCompilerPlatform
uninstall-package Microsoft.Net.Compilers
I also tried updating the web.config (and removing the references):
<system.codedom>
<compilers>
<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=\"Web\" /optionInfer+" />
</compilers>
</system.codedom>
I still get the 'roslyn' folder when publishing.
Is this issue possible because the Visual Studio solution was created in a earlier version of VS but the web project was created under VS2015?

I know this is old, but maybe it still helps someone.
The reason you still get the 'roslyn' folder is your .csproj project file. Open it for editing and remove the <Target ...> tag (incl. subtags) referencing the 2 NuGet packages you had to remove the references to.
In my case, there was only one (Microsoft.CodeDom.Providers.DotNetCompilerPlatform), but according to this question, there might be tags for both (see Brian's answer).

Related

Problems updating an application in IIS

I have an application written in aspx. The application, launching it from visual studio 2017 works correctly, using any browser.
But when publishing it, and running it on the server, I get the following error:
Parser error message: Could not locate provider type CodeDom "Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version = 2.0.0.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35".
I have tried with all the versions available in the Nuget Package Manager and I always get the same error, changing the installed version.
What I do is publish the application in the directory and upload it to any directory on the server. Enter the ASPX of the project and I get that error.
Is there any way to solve this?
The project was already installed previously, and I just have to update the source.
The project settings
The two extensions that give me problems
I have read in multiple sites that changing the version of the CodeDom, and I have followed the instructions to the letter and it has not worked
Just need to comment system.codedom tag in web.config file this work for me. like this
<!--<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.3.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.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+" />
</compilers>
</system.codedom>-->

Razor & null propagation - not working under explicit C# 6 MVC 5 project

Current project:
ASP.NET 4.6.2
MVC 5
Visual Studio 2015 Community v14.0.25431.01 Update 3
Installed the CodeDOM Providers for .NET Compiler nuget package via Project -> Install C# 6
Confirmed that I do have the compiler element in my Web.Config and that it is referencing C# 6
My Razor code:
#if(Session["Type"]?.ToString() == "Insurance") {
<text>policy of insurance</text>
} else if(Session["Type"]?.ToString() == "Warranty") {
<text>policy of warranty</text>
} else {
<text>protection policy</text>
}
Visual Studio explicitly flags this with an error,
Feature 'null propagating operator' is not available in C# 5. Please
use language version 6 or greater.
And Visual Studio is explicitly using C# 6:
When I try to run the page itself, I get an error:
CS1525: Invalid expression term '.'
which shows that it is explicitly going after the period following the question mark.
This project was explicitly started as a C# 6 project, and I am quite confused as to why it is derping back to C#5.
Another strange issue: this is working just fine both in debug as well as on my local test setup (I publish to the filesystem, view using local IIS), but when I upload to the server (which has many, many other C#6 sites) it craps out. This is the first razor-side quirk I have ever run across that actually throws an error this badly.
I was having a similar problem and found that I was missing the following from my Web.config file:
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.8.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /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.8.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+" />
</compilers>
</system.codedom>

CodeDom provider can't be located after another application deployed

I had two web applications deployed in a site under IIS 7.5
site.com/myApp
site.com/anotherMyApp
Now another devs deployed their app as root application
site.com/
Now when I access site.com/myApp or /anotherMyApp it throws:
The CodeDom provider type
"Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider,
Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35" could not be
located.
Source error :
Line 54: <system.codedom>
Line 55: <compilers>
Line 56: <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" />
Line 57: <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=\"Web\" /optionInfer+" />
Line 58: </compilers>
Source File: C:\inetpub\wwwrootprettysite\THEIR APPLICATION\web.config
Questions
Why is this happening?
Why is the "source error" in their application's webconfig and how does it affect my application?
How do I fix my applications without breaking theirs?
To clarify :
Application hierarchy is correct, their application should be
installed in root.
.NET framework installed is 4.5.2
Their application is using Roslyn compiler which is supplied in bin/roslyn
My applications web.configs have no <system.codedom> section.
Your app inherits the config from its parent app, and your app doesn't have Microsoft.CodeDom.Providers.DotNetCompilerPlatform. That's why you see that error. There are several options.
Override system.codedom setting in your web.config
Install Microsoft.CodeDom.Providers.DotNetCompilerPlatform nupkg in your app

Deploying ASP.NET MVC4 App to GoDaddy Compiler issue

Have seen several posts about deploying MVC apps to GoDaddy. None of them seem to address the issue we are having. We have followed the advice about checking runtime versions, IIS pipeline modes, publishing and copy local to true on assemblies so all works on GoDaddy.Com.
The issue we are having is that when we try to visit the site we get a Group Policy exception because ASP.NET runtime is trying to invoke the C# compiler.
[Win32Exception (0x80004005): This program is blocked by group policy. For more information, contact your system administrator]
[ExternalException (0x80004005): Cannot execute a program. The command being executed was "C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe".........
We have gone through the publish settings and elected to precompile the site. That didn't fix the issue. Have looked at the site and there are no CS files deployed. The Global.asax file does reference a codebehind file. Since we precompiled the site we tried deleting the global.asax file and that doesn't fix the issue either.
Any thoughts would be great.
I have struggled with the same problem for months. And finally solved it. In the plesk on godaddy I changed the ASP.Net settings. First changed CAS-trustlevel to Full. Then I changed in the Web.config of my project the following:
Add trust level full to the system.web
Remove the compilers in the system.codecom
<system.web>
compilation debug="true" targetFramework="4.5.2"/>
<httpRuntime targetFramework="4.5.2"/>
<trust level="Full"/> <!-- Just add this to the webconfig -->
</system.web>
<system.codedom>
<!-- All is removed between the 2 tags-->
</system.codedom>
and that solved my problem.
You have to remove the compilation info from the web config and it will work.
In addition to precompiling (check the box in your publish settings), add the following to your Web.Release.config:
<system.web>
<trust level="Full" xdt:Transform="Insert" />
</system.web>
<system.codedom xdt:Transform="Remove" /> <!-- No compiling on server, GoDaddy blocks it. -->
UPDATE (1/27/2017):
It appears (at least on my account) that removing system.codedom is no longer required.
I had same issue on GoDaddy hosting.
To fix it follow these steps.
Step 1: Choose "Precompile during publish" in Web Deploy settings.
Step 2: <trust level="Full" /> in <system.web> in Web.config
I removed the Roslyn nuget package like explained in the link below, but it's a workarround.
https://social.msdn.microsoft.com/Forums/en-US/442b100a-2b88-4ac4-b655-0c1345791f15/roslyn-cscexe-web-api-2-on-hosting-server?forum=msbuild
This problem happens with a clean mvc 5 web project from visual studio 2015 template.
I contacted the godaddy support, let's see what they do.
Excellent. I also have same problem. However, my hosting vendor is arvixe.
Add >trust level="Full" />" under >system.web> section in Web.config
comment out >compilers> section of the >codedom> in Web.config
The problem Fixed!!!
csc.exe compiler error after publish
comment below on web.config
<!--<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.3.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.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+" />
</compilers>-->

How to specify a CompilerVersion for aspnet_compiler.exe without a web.config?

When you precompile a directory that doesn't contain a web.config, the aspnet_compiler.exe defaults to CompilerVersion 2.0 and 3.5 code fails to compile. Is the following minimal web.config the only way to specify the CompilerVersion?
<?xml version="1.0"?>
<configuration>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" warningLevel="4"
type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<providerOption name="CompilerVersion" value="v3.5"/>
<providerOption name="WarnAsError" value="false"/>
</compiler>
</compilers>
</system.codedom>
</configuration>
We integrated asp.net precompilation with our build and integration environments and don't use web.configs for our control library components
Here you can find its parameters. Also note that ASP.NET Compilation tool is not available with versions of ASP.NET earlier than ASP.NET version 2.0.
For .NET 2.0 these are the steps you need to do
Start > run and type cmd.
set path=%windir%\Microsoft.NET\Framework\v2.0.50727
aspnet_compiler –v / –p c:\myproject\testsite c:\testcompile
I think that for other versions of .NET you have to cd to corresponding directory.
Also read this. You might find it useful.

Resources