Nant aspnet_compiler.exe release build - asp.net

I have the following nant task:
<!--Compiles the possible release candidate to be used for further testing and possible release -->
<target name="createReleaseCandidateJob">
<xmlpoke file="${nant.project.basedir}/${webApplicationProjectName}/Web.config"
xpath="/configuration/system.web/compilation/#debug"
value="false" />
<exec basedir="." program="C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler.exe"
commandline="-p ${webApplicationProjectName} -v / ${releaseCandidateOutputDir}"
workingdir="."
failonerror="true"
/>
<echo>Completed Compile RC Job</echo>
</target>
I also have the following line of code included in my project:
myVersion = "2.0b";
#if DEBUG
myVersion = Guid.NewId().ToString();
#endif
this is used when loading certain assets (swf files) by being appended as a querystring parameter and ensures that when debugging a cached version isn't received but is manageable once released.
However, after what I believed should be compiling a relase build, the version is still being set as a Guid indicating I'm not achieving a release build yet. I've checked the web.config and the value of debug is changed to false so I'm assuming I'm missing some setting in the aspnet_compiler.exe arguments, but I cant find anything which indicates such in the documentation.

The aspnet_compiler can tell the difference between a debug and 'retail' compile using the web.config value, but the conditionals are usually passed as an argument to the compiler (see this) by whatever is driving the build (e.g. Visual Studio, NAnt or whatever). The ASP compiler doesn't have that, so you need to include them in the codedom section of the web.config file:
<system.codedom>
<compilers>
<compiler
language="c#;cs;csharp"
extension=".cs"
warningLevel="4"
compilerOptions="/d:DEBUG"
type="Microsoft.CSharp.CSharpCodeProvider,
System, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089" />
</compilers>
</system.codedom>
Here, compilerOptions provides the #DEBUG definition you need. That will be picked up by the compiler itself when invoked by aspnet_compiler and should be reflected in the #conditional blocks in your code. So remember to change that as well when you switch the other debug flag in your web.config.

Related

What would cause a VB.NET DLL to fail in IIS when it works well when called by executable code?

For the last 5-6 months I have been fighting a battle with VB code calling a c++ DLL. I have asked numerous questions on StackOverflow only to have all of them voted out of existence.
I have finally found a way of compiling my code (no help from Stackoverflow) that will work well with the C++ DLL. It appears that when I compile my VB.NET module and I use a 4.0 framework it works perfectly, no more memory issues with calling c++. Frameworks > 4.0 cause the protected memory errors.
My VB.NET code is itself a DLL and I call it from both compiled .EXE programs as well as uncompiled vb.net code from ASP.NET. When I compile it into other VB.NET programs everything works well. When I run it from ASP.NET I get;
Attempted to read or write protected memory.
This is the same error I would get when I previously compiled with a Framework > v4.0. I have modified my web.config file adding;
<compilation debug="false" targetFramework="4.0"/>
and
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" warningLevel="4" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<providerOption name="CompilerVersion" value="v4.0" />
<providerOption name="OptionInfer" value="true" />
<providerOption name="WarnAsError" value="false" />
</compiler>
With no change in behavior. Since the memory error is similar to what I get when I execute this same code compiled with a framework > 4.0 my assumption is IIS is executing the code with a framework > 4.0.
The questions as best I can formulate them are;
How can I verify what framework the DLL is executing in?
How can I control that framework?
Hopefully this question lasts long enough to get an answer, rather than voted down the tubes.

Azure site : Compiler Error Message: CS1056: Unexpected character '$'

I am trying to host my application in Azure but getting below error:
Compiler Error Message: CS1056: Unexpected character '$'
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.2623.0
I have used string concatenation using '$' sign.
This works fine in my local machine, but throws the compilation error.
How to set the right framework version in Azure and avoid the above exception.
Thanks,
Sharath
Lex should get credit for sending this in the correct direction. I want to confirm that this is the correct path and fixes the issue and give a little more detail. I was having the same issue and error message "Compiler Error Message: CS1056: Unexpected character '$'" when trying to deploy a ASP.NET app to Microsoft Azure App Service and indeed the solution was to add the Roslyn compiler to the project. It appears by default the built in compiler used on Microsoft Azure App Service only supports up to C# 5 language features and Roslyn is needed to compile and use the C# 6 features. Note I am deploying CS files for my project and not compiled DLL files.
Install Roslyn In Project
In Visual Studio 2017 Select "Tools" -> "NuGet Package Manager" -> "Manage NuGet Packages for Solution..."
From the tabs select "Browse" and then search for "Microsoft.CodeDom.Providers.DotNetCompilerPlatform"
Select "Microsoft.CodeDom.Providers.DotNetCompilerPlatform" from the search results then over on the right check the project name you want to add it to and then click the "Install" button.
Rebuild your Solution and make sure it still builds.
Deploy with Roslyn
You will notice installing the DotNetCompilerPlatform package added a section to your Web.config file that looks something like this, make sure this section gets added to your deployed Web.config:
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.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=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+"/>
</compilers></system.codedom>
You will also notice installing the DotNetCompilerPlatform package and building your solution added some files to your Bin folder, make sure these files (including the whole "roslyn" folder and all the files in it) get put in the Bin folder of your deploy: Bin folder files to deploy
That was all it took to get my website back up and running with C# 6 language features, hope it helps.
You can install Microsoft.Dotnet.Compilers package and then compile your site again.
Refer this page - Project builds fine with Visual Studio but fails from the command line

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>-->

custom compiler contants in vb.net web site project

I'm working on a web site project on vb.net - asp.net 4 - visual studio 2010.
I need to implement a part of code that is used only when debug compilation is chosen within visual studio, e.g.:
' do something
#if DEBUGCONST
' debug mode! do something else
#end if
' proceed as usual..
Unfortunately this is not a web application project, therefore it doesn't come with a complete "property page" (where you can change compilers constant easily).
Googling for an answer, I found:
http://msdn.microsoft.com/en-us/library/a15ebt6c%28v=vs.100%29.aspx
..and I changed my web.config in this way:
<system.codedom>
<compilers>
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" compilerOptions="/define:DEBUGCONST"></compiler>
</compilers>
</system.codedom>
Unfortunately, even if it compiles fine, the DEBUGCONST is never defined and the "debug code" is never executed.
Is there something I'm missing?
Thank you in advance for any help!

Why do I need to specify the compiler version on web.config to use extension methods inline?

I have an extension method on HttpRequest that I'm trying to use inline on different aspx pages.
Despite I've added the correct import to the aspx I get an error saying that the method doesn't exist. The extension method works perfect on code behind.
Compiler Error Message: CS0117: 'System.Web.HttpRequest' does not contain a definition for...
In order to fix this, I had to add this web.config declaration
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CSharp.CSharpCodeProvider,System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4">
<providerOption name="CompilerVersion" value="v3.5"/>
<providerOption name="WarnAsError" value="false"/>
</compiler>
</compilers>
</system.codedom>
I found that here but I have no idea why I need this declaration.
I'm not sure what's for and I'm concerned that it might have some side effect.
Do you know why I need this declaration and how I could avoid it?
Extension methods were introduced in .NET 3.5. By default, inline code is compiled with CompilerVersion v2.0. You need to add the block you specified to instruct the runtime to compile language features introduced in .NET 3.5, hence the CompilerVersion value of "v3.5".
The problem is specific to ASP.NET, as extension methods compile in normal applications under the CLR 2.0 compiler.

Resources