How to make Roslyn the default Compiler for ASP.NET and put it in GAC? - asp.net

We are using ASP.NET 4.6 with website/web application projects.
We added the Roslyn Complier via Nuget Package to our website project and VS.NET updated the web.config plus added a Roslyn folder under "bin".
Inside this folder there are a number of dlls and exe files.
The documentation specifies to gain the best ASP.NET Startup time, it is best to Ngen and GAC the Roslyn assemblies.
I am not sure how I can use Ngen.exe or other tools to move it correct to GAC.
here is the source:
http://blogs.msdn.com/b/webdev/archive/2014/05/12/enabling-the-net-compiler-platform-roslyn-in-asp-net-applications.aspx
See this section: Announcing the first preview of new CodeDOM Providers for .NET Compiler Platform (“Roslyn”)

Related

Compiling ASP.NET project versus NET4.0 with NET4.5 installed

I have an ASP.NET project that was working correctly compiled with Visual Studio 2010 and NET4.0.
Then I have installed VS Express 2012 and NET4.5 and I always get an Exception trying to open a SqlConnection.
Can I have some chance to recompile my project targeting NET4.0 (so without disinstalling 4.5) and have it working?
In VS Express 2012 I have this web.config:
<system.web>
<compilation debug="true" targetFramework="4.0"/>
The referenced assemblies correctly target the v4.0, for example:
Assembly System.Data
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Data.dll
EDIT 2
As this blog http://blogs.msdn.com/b/msbuild/archive/2007/04/12/new-reference-assemblies-location.aspx and also this answer https://stackoverflow.com/a/8543850/1012244 explains very well, there is a BIG difference betweeen Referenced Assemblies (folder contains those assemblies that ship with the x.xx Framework which are useful for referencing during the design and build of new components) and Runtime scenario (At runtime, these components will still be loaded from the GAC in most cases).
However, when I run the project I always get the Exception, as if the project actually was using NET4.5... Why?
PS. If I deploy this project on a production server machine with only NET4.0 installed, the connection is fine.
(This is clear now: Installing Net4.5 essentially replaces Net4.0)
UPDATED QUESTION -
Can I have some chance to recompile my project targeting an OLD NET4.0 .dll (System.Data.dll in my case) instead of the new Net4.5 dll?
EDIT - Additional info
At this MSDN link http://msdn.microsoft.com/en-us/library/ff602939.aspx I found:
If you determine that a change in the .NET Framework 4.5 has broken your application, check the Runtime Settings Schema to determine whether you can use a runtime setting in your application configuration file to restore the previous behavior.
Could this help me? And how?

EF 5 and WebSite conflict

I'm having problems with a website project and entityframework 5.
I'm going to put some background: The project type is Website, not web application or MVC, so when deploying, I simply copy all the files to the server and all is compiled when the first visit arrives. And that is what i think is causing the problem.
The project is targeting .Net 4.0 so when I install EntityFramework from nuget, the dll file version is 4.4. Running the project from VisualStudio with IIS Express is fine ( because VisualStudio knows that the target framework is 4 and compiles the project using .Net framework 4 dll ) but when copying the files to the production server where .Net framework 4.5 is installed, when first visit arrives, the website is compiled against the .Net framework 4.5 dlls and a problem appears because EntityFramework 4.4 contains definitions for classes ( like Column ) that are also contained inside the dataannotations dll from .Net 4.5.
The type 'System.ComponentModel.DataAnnotations.Schema.ForeignKeyAttribute' exists in both 'c:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4.0.0.0__31bf3856ad364e35\System.ComponentModel.DataAnnotations.dll' and 'c:\Users\jyuste\AppData\Local\Temp\Temporary ASP.NET Files\portalempleado\4700d3ec\2c948b16\assembly\dl3\1c8b81c9\750c5018_1e5dce01\EntityFramework.DLL'
I suppose that upgrading the project to .Net 4.5 and updating the EntityFramework reference would solve the problem, but I can't do it right now.
Do you think that there is another solution?
From what you write, a possible solution would be to change the deployment procedure.
Instead of copying C# source files to a destination server, first publish the site locally to any directory. Publishing could be done with the "Build/Publish Web Site" option from the VS menu.
This will compile all your source files and create a deployment-ready sturcture containing only declarative code (*.aspx,*.ascx,*.asmx,etc) and the /bin folder containing *.dlls with compiled C# code.
Only then copy the published structure to the destiation server.

Where does ASP.NET look for binaries when you compile an ASP.NET 4 web project under x86 (32-bit)?

I'm developing an ASP.NET MVC 4/Web Api application in VS 2010 on my 64-bit dev machine. I have IIS installed and am running the project under IIS. Because I need to interface with a third party component, I have to change the project build configuration to x86 (I'm currently in the Debug build).
In IIS, I configured the application to use an application pool that allows 32-bit processes. However, when I ran my site, I noticed that code changes I was making were not showing. It turns out that the assemblies being used were those found in the \bin folder. After changing the configuration, the compiler's assembly output goes to the \bin\x86\debug folder; it didn't look like IIS was looking there.
I temporarily switched the configuration back to "Any CPU", right-clicked the project node, and selected the Clean option. This removed all the stale assemblies in the \bin folder. I then switched back to the x86 configuration -- rebuilt the project for good measure -- and tried to run the project again. Now it wasn't finding any assemblies at all. I'm getting errors like:
Could not load file or assembly 'System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies
System.Web.Providers -- and all the rest of the assemblies -- reside in \bin\x86\debug.
Is IIS supposed to know to look there?
Is Visual Studio supposed to copy the assemblies up two levels to the \bin folder?
If the latter, that is clearly not happening. Thanks for any insight.
The solution was simply to set the Output Path to bin in the Build tab of the project properties. :-)

How to add reference to Microsoft.Office.Interop.Word.dll while copying an asp.net app from dev server to test server

I am referencing Microsoft.Office.Interop.Word.dll in my asp.net web application at development server.
No i need to move this app from development server to testing server.
I can't see the dll in the bin folder of the app as it is pointing to GAC.
How should i reference the above specified dll in testing server?
Do we need to do anything with web.config?
Please advice.
Thanks,
Ram
Visual Studio uses different sets of the PIAs on the development computer. These different sets of assemblies are in the following locations:
A folder in the program files directory.
These copies of the assemblies are used when you write code and build projects. Visual Studio installs these assemblies automatically.
The global assembly cache.
These copies of the assemblies are used during some development tasks, such as when you run or debug projects that target the .NET Framework 3.5. Visual Studio does not install and register these assemblies; you must do this yourself.
Link
If not found DLL you have to download from internet....

Step into referenced .Net 3.5 assembly from Asp.Net 4 project

Can I step into .net 3.5 assembly that is referenced by an Asp.Net 4 application?
We have a bunch of dll's that are used in our projects. The assemblies are targeting framework 3.5. I also have the source code for the assemblies. In framework 3.5 projects I could step into the referenced assemblies, even though the project only referenced the assemblies, if I set the Solution->Properties->Debug Source Files -setting to the location of the assemblies' source code files. Now in an Asp.Net 4 project the same doesn't work. I cannot step into the referenced code.
If I open a source file directly in Visual Studio (File-Open->navigate to source code location) and put a breakpoint in a file I know will be run it says "...breakpoint will not be hit. No symbols have been loaded..." when attaching to w3wp.exe and selecting to debug "Managed (4.0)". If I attach it to "Managed (2.0)" the breakpoint does not hit either.
Please advice,
Mathias
So you have your compiled dlls under 3.5 framework, and also you have source code for them, right? Have you tried opening a solution, which contains the project, and attaching it to w3wp.exe? Also ensure your dlls were compiled with debug information.
Another way is to use .NET Reflector to step in dlls without source code at all.

Resources