How disable nuget package restore when adding new MVC5 Views - asp.net-mvc

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

Related

Creating a new package and adding it ot nuget source in Visual Studio

I have a Asp.Net MVC solution, that needs to be added as a Nuget package, which can be used as a shared component by internal applications.
I have googled a bit and found that we can create a nuget package only by using a class library. project.
In my case how can I create a nuget package using a web application ? Or should I create a class library project referencing the the Asp.Net MVC application dll ?
Previously this whole application as a dll was referenced by other components/ projects. Now I need to move this dll to the nuget source so that it can be still used by other projects by downloading it from nuget manager.
Thanks in advance.
You can add a .nuspec file defining your dll and its dependencies and add a post build call to create the package.
Example nuspec file:
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd" >
<metadata>
<id>myproductid</id>
<version>$version$</version>
<title>some title</title>
<authors>me</authors>
<owners>myself</owners>
<projectUrl>http://www.example.com</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>...</description>
<releaseNotes>First nuget release.</releaseNotes>
<copyright>Copyright 2020</copyright>
<dependencies>
<dependency id="AutoMapper" version="9.0.0" />
<dependency id="jQuery" version="3.3.1" />
<dependency id="Microsoft.AspNet.Mvc" version="5.2.7" />
<dependency id="Microsoft.AspNet.Razor" version="3.2.7" />
<dependency id="Newtonsoft.Json" version="12.0.2" />
<dependency id="System.Reflection.TypeExtensions" version="4.6.0" />
</dependencies>
</metadata>
<files>
<file src="bin\My.WebApplication.dll" target="lib\net461" />
</files>
</package>
The post build event, in my case, looks like this:
if ($(Configuration)) == (Release) nuget pack "$(ProjectPath)" -Prop Configuration=Release -OutputDirectory "K:\nuget"

Visual Studio 2019 Enterprise automatically adds COMPLUS_ForceENC environment variable while debugging/running using IIS Express

I'm using Visual Studio Enterprise 2019 version 16.3.10. Whenever I run/debug my web project using IIS Express, it adds COMPLUS_ForceENC environment variable as shown below:
<environmentVariable name="COMPLUS_ForceENC" value="1" />
Here is the screen print,
Every time I need to undo this change before committing my changes to source control. Please can anyone assist me on how to avoid this change?
After a long time, I got response from Visual Studio developer community.
The web.config only gets updated if you have the following section present in the web.config. You can remove the following from the web.config and running the application will not update the existing web.config. if you are using IISExpress, You can alternatively remove the full web.config from the project. web.config is not required in the project for running in IISExpress.
<handlers>
<remove name="aspNetCore" />
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="InProcess">
<environmentVariables>
<environmentVariable name="ASPNETCORE_HTTPS_PORT" value="44370" />
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
<environmentVariable name="COMPLUS_ForceENC" value="1" />
</environmentVariables>
</aspNetCore>
Here is the link for the same.
Adding this Enivronment Variable seems to be a workaround for enabling the "Edit and Continue" debugger feature.
Source

VS 2015 : Could not load file or assembly 'System.Web.WebPages.Razor, Version=2.0.0.0

I am running a solution which contains different projects. However, i am trying to run a project (class library) which contains wcf services using Visual Studio 2015 and framework 4.6 (on windows 8 OS, IIS Express). However it keeps showing this error in the browser:
Error:
I noticed that the calling assembly of Razor 2.0 is "System.Web.Mvc" Version 4.0.0.1:
Calling assembly : System.Web.Mvc, Version=4.0.0.1, Culture=neutral,
PublicKeyToken=31bf3856ad364e35.
However, System.Web.MVC dll is not referenced in this project, the references in the project are in the image below:
Although, it is not referenced it always appears in the bin folder, even when i clear it. And may be that's why it is trying to call "System.Web.WebPages.Razor" version 2.0.
Clarifying any clues of the problem:
I have no related assembly in the Web.Config that calls System.web.mvc
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
also not included in package config:
<packages>
<package id="EntityFramework" version="6.1.3" targetFramework="net46" />
<package id="Microsoft.AspNet.Providers" version="2.0.0" targetFramework="net451" />
<package id="Microsoft.AspNet.Providers.Core" version="2.0.0" targetFramework="net451" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net46" />
<package id="PostSharp" version="4.3.5-alpha" targetFramework="net46" />
<package id="System.Web.Providers" version="1.2" targetFramework="net451" />
</packages>
not included as a reference
I am wondering about whats going on? may another project affects it!
Also i have tried to use nugget to update the packages (uninstalled and reinstalled), but still in the same situation.
A possible reason of the problem:
I also noticed there is a "Gobal.asax" file in this project which uses "MvcApplication" class that implements "System.Web.HttpApplication" which may be a good reason of the problem.
Any help is appreciated.
Solution: install Microsoft.AspNet.Webpages first release of version 2.0 via nuget manager.
I would start by looking at assembly binding failures - this will show you which assembly is requesting that failing binding.
There is a handy little tool you can use to view your binding failures. This should help you track it down.
https://msdn.microsoft.com/en-us/library/e74a18c4(v=vs.71).aspx
Good luck!
in my case, the error was after deploying, and the issue was a reference in a web.config within a sub folder of that server.
i troubleshot this by remoting into that machine and browsing the site locally (or you can enable remote errors in web.config)
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
So be sure to search all your files for 2.0.0.0 or System.Web.WebPages.Razor to make sure there is no reference somewhere!
I was getting this error, but the project from which the error is throwing has the Microsoft.AspNet.Webpages installed properly. Then I realised that the WCF services which are kept in a separate project lost it's MVC installation.
So installing Microsoft.AspNet.Mvc in my other project fixed this error for me.

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

MVC4 Bundling slow when using Scripts.Render

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

Resources