MVC4 Bundling slow when using Scripts.Render - asp.net-mvc

My asp.net MVC4 web project is running very slowly when serving a simple page that renders bundled scripts. However, when I use a 'hardcoded' script tag on the page with the source attribute of the virtual bundle path then performance is much better:
#Scripts.Render("~/bundles/scripts") ~ 4 seconds
vs
<script src='#Scripts.Url("~/bundles/scripts")'></script> < 1 second
My BundleConfig.cs has no special configuration, this is exactly as it appears:
bundles.Add(new ScriptBundle("~/bundles/scripts").Include(
"~/Scripts/jquery-1.7.2.min.js",
"~/Scripts/jquery.validate.min.js",
"~/Scripts/jquery.validate.unobtrusive.js",
"~/Scripts/jquery-ui-1.9.0.custom.min.js",
"~/Scripts/bootstrap.min.js",
"~/Scripts/bootstrap-modal.js",
"~/Scripts/bootstrap-dropdown.js",
"~/Scripts/bootstrap-tooltip.js",
"~/Scripts/bootstrap-typeahead.js",
"~/Scripts/bootstrap-transition.js",
"~/Scripts/bootstrap-popover.js"));
My web.config is even configured to optimize in Debug but I have tried running in Release mode and still get the same result:
<compilation optimizeCompilations="true" debug="false" targetFramework="4.0" />
Any ideas why Scripts.Render is so slow?

The problem was with the outdated package I had installed. A simple Update-Package in package manager console and I went from
<package id="Microsoft.AspNet.Web.Optimization"
version="1.0.0-beta2" targetFramework="net40" />
to
<package id="Microsoft.AspNet.Web.Optimization"
version="1.0.0" targetFramework="net40" />
Now Scripts.Render() is peforming much better :-)

Related

How can I prevent <aspNetCore /> tag from being auto-generated in web.config when having in-host processing enabled?

Recently, I was told by Microsoft that maybe in-host processing could solve some of my CPU issues (running .NET Core 2.2).
So I went into my .csproj and added:
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
Now, whenever building in Visual Studio, this gets forcefully inserted into my web.config:
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" hostingModel="InProcess">
<environmentVariables>
<environmentVariable name="ASPNETCORE_HTTPS_PORT" value="44384" />
<environmentVariable name="COMPLUS_ForceENC" value="1" />
<!--<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" /> ALWAYS RE-APPEARS !!-->
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
</environmentVariables>
</aspNetCore>
Notice the ASPNETCORE_ENVIRONMENT being set. If I uncomment it, or remove it, it will re-appear.
This is a problem because the web.config goes into my repo, then DevOps builds and publishes my app with the following App settings:
-ASPNETCORE_ENVIRONMENT Test
However, environmentVariable set in the web.config completely overrides this.
How can I prevent Visual Studio from messing with my web.config and not respecting my choices?

How disable nuget package restore when adding new MVC5 Views

In a MVC project using Visual Studio 2015, i have configured the references to use dlls without using nuget. But when i'm adding a new view (MVC5 View Page, MVC5 Partial Page, etc), visual studio automatically add nuget packages to the project that are already referenced. Why? Is there a way to disable nuget completly?
Using Add -> View, my references are not altered and the packages are not downloaded
Using Add -> MVC5 View Page, MVC Partial View or the other ones, Visual Studio add a packages.config and change the references to the newly downloaded libraries
Here's the package that VisualStudio add when i'm adding a new View :
<packages>
<package id="Microsoft.AspNet.Mvc" version="5.2.3" targetFramework="net452" />
<package id="Microsoft.AspNet.Razor" version="3.2.3" targetFramework="net452" />
<package id="Microsoft.AspNet.WebPages" version="3.2.3" targetFramework="net452" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net452" />
</packages>
I have the latest version of Visual Studio 2015 with Update 2 but this behaviour was there before the update
I added the line <RestorePackages>false</RestorePackages> to the project file without success

"Unable to satisfy package dependency constraints" with Breeze.Server.WebAPI2

I am trying to add the Breeze.Server.WebAPI2 Nuget package to Visual Studio Community 2015 RC. When I click on install I get "Unable to satisfy package dependency constraints"
The listed dependencies are:
Microsoft.AspNet.WebApi.OData (>= 5.2.2 && < 6.0.0)
Microsoft.AspNet.WebApi.WebHost (>= 5.2.2 && < 6.0.0)
Breeze.Server.ContextProvider (=1.5.4)
WebActivator
I tried adding the missing dependencies using their own packages, and now my packages.config looks like this:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Breeze.Server.ContextProvider" version="1.5.4" targetFramework="net452" userInstalled="true" />
<package id="Microsoft.AspNet.WebApi" version="5.2.3" targetFramework="net452" userInstalled="true" />
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net452" userInstalled="true" />
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net452" userInstalled="true" />
<package id="Microsoft.AspNet.WebApi.OData" version="5.5.1" targetFramework="net452" userInstalled="true" />
<package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.3" targetFramework="net452" userInstalled="true" />
<package id="Microsoft.Data.Edm" version="5.6.0" targetFramework="net452" userInstalled="true" />
<package id="Microsoft.Data.OData" version="5.6.0" targetFramework="net452" userInstalled="true" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net452" userInstalled="true" />
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net452" userInstalled="true" />
<package id="System.Spatial" version="5.6.0" targetFramework="net452" userInstalled="true" />
<package id="WebActivatorEx" version="2.0.6" targetFramework="net452" userInstalled="true" />
</packages>
But I still get the same error
EDIT
To get around the problem I downloaded Visual Studio 2013 Express and used it to create the project and add the package. Then I added the project to Visual Studio 2015. Untidy, but I'm up and running.
Two points to this response:
Firstly, according to the NuGet Package Manager GitHub issue tracker, the message you have received is a known issue, in that the identity of the problematic package should have been included in the error message, rather than the generic 'Unable to satisfy package dependency constraints'.
https://github.com/NuGet/Home/issues/241
As indicated in the Issue tracker, this has been resolved, but the version of the NuGet Client that includes the fix has not yet been released.
I have observed the same behaviour for other packages with Visual Studio 2015 RC, for which the latest NuGet Package Manager client (as of writing) is 3.0.60410.213.
While debugging this error on other packages, it led me to a potential resolution:
Secondly By default the NuGet Package Manager in Visual Studio 2015 RC is set to install packages with the Dependency Resolution behaviour set to 'lowest'. In one or two cases where I have encountered the "Unable to satisfy package dependency constraints" error, adding a package with Dependency Resolution behaviour set to 'highest' has resolved this issue, presumably due to either incorrect dependencies specified in the parent NuSpec manifest, or incompatibilities as specified in the dependency graphs manifests.
One example of the latter a higher version of a package is installed in Visual Studio 2015 RC project templates than is supported by a third-party package in the dependency chain. The NuGet bug fix mentioned above should make identifying these situations much easier.
I had the same problem, I had Nuget version 3.0.60410.213. I was trying to install EasyNetQ but I kept getting that error also. I tried using "highest" in Dependency Resolver, but no cigar.
My solution was to install the dependency individually. I installed the RabbitMQ.Client package, then EasyNetQ would install.

Could not find compiled resource bundle 'components' for locale 'en_US'

I'm building my Flex 4.6 project using ant. The Ant script also compiles a css file to swf, but when I run the application, it gives an error: Could not find compiled resource bundle 'components' for locale 'en_US'.
Here is the piece of my ant script that builds the style file:
<mxmlc
incremental="true"
fork="true"
optimize="true"
debug="false"
file="${app.dir}/src/main/resources/stylepacks/${stylepack}/styles.css"
output="${output.dir}/stylepacks/${stylepack}/styles.swf">
<source-path path-element="${app.dir}/src/main/flex" />
</mxmlc>
I've tried many possible solutions that I found, such as including the resource bundles:
<include-resource-bundles>components</include-resource-bundles>
or
<include-resource-bundles bundle="components" />
and referncing the Flex resource bundles:
<source-path path-element="${FLEX_HOME}/framework/locale/en_US" />
but it all doesn't seem to work.
The application and the stylesheet uses both HALO and Spark elements, so I've tried with both themes, but then the build fails:
<compiler.theme file="${theme}" />
Does anyone have any more suggestions??

Log4Net works on Dev machine, fails when deployed to shared host (using same db/connstring)

I have log4net configured and working fine on my local machine, however when I deploy to my host (godaddy) it fails silently. I am using the same database/config file on my dev machine, and on the host. My log4net reference is set to copy local, and the log4net.dll, .pdb, and .xml exist in the bin on the host. This is an asp.net mvc app.
Edit: No exceptions are thrown, and the application runs as expected (minus the logging)
This is running on SQL Server 2005
The webhost is IIS 7
salient details of my config are:
<root>
<level value="DEBUG" />
<appender-ref ref="AdoNetAppender" />
</root>
<appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
<bufferSize value="1" />
<connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
Anybody have any ideas on things to check?
In my experience, log4net usually swallows any internal errors, simply resulting in log statements that do not produce any results.
What you may want to try is enable log4net's internal logging. You can do this by adding the following to your appSettings section:
<add key="log4net.Internal.Debug" value="true" />
This sets the property LogLog.InternalDebugging to true. log4net will now log to the standard output and error streams and to configured trace listeners.
You can use the following configuration to capture any messages logged to tracing:
<system.diagnostics>
<trace autoflush="false" indentsize="4">
<listeners>
<add name="myListener"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="c:\TextWriterOutput.log" />
<remove name="Default" />
</listeners>
</trace>
</system.diagnostics>
All messages logged by log4net internally will appear in TextWriterOutput.log. If you get a SecurityException when you add the trace listener to your configuration, then very probably the apppool identity does not have sufficient rights to create a file at the specified location (in the example: c:\). Try another location or give the apppool identity sufficient rights.
I've just been able to resolve this problem by downloading and using the latest build of log4net (revision 1072765) from SVN repository http://svn.apache.org/viewvc/logging/log4net/trunk/
Apparently this problem has been fixed long time ago but who knows when log4net 1.2.11 is going to be released.

Resources