Taghelper: Cannot resolve TagHelper containing assembly - asp.net-mvc

I cannot get a custom TagHelper to work in my ASP.NET v5 project. The custom TagHelper is located in the web project itself. I tried following this sample this sample from CodeProject and this tutorial too.
When I try to use the tag without addTagHelper:
nothing is transformed, no breakpoints hit in the tag helper.
When I try to #addTagHelper "*, MyWebApplication" to the Viewcomponent, the error is MyWebApplication'. Error: Could not load file or assembly 'MyWebApplication'.
What am I missing?
Tool versions:
Microsoft Visual Studio Enterprise 2015 RC
Version 14.0.22823.1 D14REL
Microsoft .NET Framework Version 4.6.00057
Microsoft.AspNet.Mvc 6.0.0-beta4

The advertised signature for addTagHelper is
#addTagHelper "className/Filter", "assemblyName"
Behaviour actually appears to be (at least for helpers in same web project)
addTagHelper "className/Filter", "folderName"
because at least into Beta6, the assembly name is the folder name and ignores the attributes in the project properties.
Here is a sample working demo
Hit F5, view cats.
Edit the project properties to change the assembly name.
Hit F5, view cats. << This should not work?!
Close solution, rename the on disk directory TagHelperDemo ->
TagHelperFolderDemo
Observe page fails until the folder name is used for addTagHelper directive
PS: #addTagHelper is required even when the TagHelper is in the same project. VS2015 re-colours the tag as purple when it is targeted by a TagHelper.

Related

Unable to add reference to certain assemblies in VS2015 MVC project

I am relatively new to MVC, so maybe I am missing something. I am using VS 2015 Community Edition, C# 2015 & .NET Framework 4.5.2.
I have an MVC solution with 2 projects: TLM and TLM.Tests. All the .cs files in both projects are happy with the following line of code:
using System.Data;
In fact, one of the .cshtml files has this line:
#using System.Data;
Now I add a 3rd project to the solution, a Class Library called TLM.Helpers, to hold commonly used code. (In ASP.NET web forms, it would have just gone in a .cs file in the App_Code folder.) However, I cannot add a using statement for System.Data to any of the .cs files in this project. In fact, I cannot even add a reference to that DLL in this project, although I see that there is such a reference in the other 2 projects.
That new project does have successful references to System, System.Collections.Generic, and System.Linq.
Other posts for similar issues suggest verifying that the project is being built for the proper Framework version. The Property page for this project does not even offer the choice of Target Framework. It does have dropdowns for "Solution DNX SDK version", which refers to "Version 1.0.0-beta5". I don't know what that refers to.
Any suggestions as to how I can refer to System.Data in this project?
Thanks.
Dan

Problems after migrating VS2013 to VS2015 in MVC

UPDATED QUESTION
I have a project that I've started in VS 2013 and was setup as the following:
MyMainMvcApp (Containing core Functionality)
MyPlugin (Containing plugable customer stuff)
MyPlugin contains some *.cshtml views as embedded resource and some controllers.
In VS2013 I was able open the Views and i had full Razor Intellisense and no issues when compiling.
IN V2015 the Error List is showing a lot of errors like
Feature 'lambda expression' is not available in C# 2. Please use language version 3 or greater.
The type or namespace name 'Mvc' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)
etc etc
Of course I have all the Assemblies referenced. And the projects even compile.
I believe that VS 2015 is just missing some config stuff in web.config or similar, so that he can resolve the stuff while having the view open in designer.
I have an app.config in MyPlugin project that has been added from Nuget.
I've put the same config stuff as my web.config in there but that didn't help.
As well I copied the MyMainMvcApp\Views\web.config into MyPlugin\Views\web.config that didn't work as well.
Any idea what the issue might be or ideas how to solve it?
I've started MyPlugin as a Class Library in VS 2013 and that worked well. Afterwards I was not able to make MyPlugin work as desired in VS 2015 designer. I've created a new MyPlugin Project as a MVC Project and copied all my code from the old library to the new.
It's a workaround but that solves my VS 2015 problems.
The fact that it's trying to utilize C# 2, is pretty concerning. Make sure your project is targeting the latest version of .NET you feel comfortable with. Since you're using VS2015, go all the way to 4.6 if you like, or if you want something a little more hardened, stick with 4.5.2. Just right-click your project in the Solution Explorer and choose "Properties". Then on the first "Application" tab, change the "Target framework" drop-down to something appropriate.

How to remove System.Web.Optimization from MVC5

I have a new ASP.NET MVC5 project. I don't want to use Microsoft bundling and minification so I removed the nuget package and the dependencies that I also don't want.
I ensured there was nothing left in the config and I cleared out \Temp\Temporary ASP.NET Files\
I am using VS2013 / IIExpress and there is nothing that references System.Web.Optimization in the aspnet.config or the applicationhost.config
...the solution builds fine but when I run it throws:
Compiler Error Message: CS0234: The type or namespace name 'Optimization' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)
Something somewhere is trying to pull in the dll, but it's not my code. Seems very odd!
Line 26: using System.Web.Optimization;
Surely it's not reference by MVC5 itself. Anyone seen this before?
I just found it in the Views folder when I did a search for 'namespaces', no idea how I missed it. I didn't even know there was a config file in the Views folder.
I found
<add namespace="System.Web.Optimization" />
in the Web.config file under the Views folder. It doesn't get removed with the package.
In Visual Studio 2012, There was a problem after creating a new Area. In Web.Config of that Area, There was a statement (line) that Visual Studio Compiler wants to use Microsoft.AspNet.Web.Optimization! And when you run the application and you want to see some of views in that Area, You get an error because of that statement (line).
Solution (1)
Delete that statement (line) Microsoft.AspNet.Web.Optimization in Web.Config of Areas (in Visual Studio 2012)
Solution (2)
You can install the Web.Optimization for your application with NUGET:
INSTALL-PACKAGE Microsoft.AspNet.Web.Optimization

ASP.NET MVC 5 Visual Studio 2013

i'm working on a project which is using mvc 5,ef 6.1, visual studio 2013. First i start coding from admin panel after its done i get back to admin panel for some changes.
Then i got those errors : http://prntscr.com/34tuby
ViewBag, Html Helper is not recognizing.
Project can compiling and working but when open a cshtml (view) file in visual studio i got those error.
for solution i tried;
Clean/Rebuild Project
Compare web.configs
Compare View web.configs
Compare project properties
Compare packages config
all packages same, web.config files same , all packages version same with working project.
-Thanks
Try checking your configuration file, as mentioned in this SO post. It's usually related to config entries not matching the correct DLL's.
I create new project and transfer all files with same namespace. And it work

Add View dialog does not work in an MVC 5 project that references an F# project

Using Visual Studio 2013, create a new ASP.NET Web Application project using the MVC template. Verify that the Add View dialog functions by right-clicking the "Views\Home" folder and choosing "Add... View".
Now add a new F# Library project to the solution. The Add View dialog should still function correctly.
Now add a project reference from the MVC project to the F# project by right-clicking the References folder, choosing Add Reference, Then browse to Solution...Projects on the left and checking the F# library project that you just added.
At this point, if you right-click the "Views\Home" folder and choose "Add... View" you will get an error in a pop-up alert box instead of the Add View dialog:
There was an error running the selected code generator: 'Object reference not set to an instance of an object.'
Workarounds include, but are hopefully not limited to:
Remove all your references to any F# projects every time you want to add a new view.
Unload any referenced F# projects, but leave the project references in place, every time you want to add a new view.
My questions are:
Are other people seeing this behavior, or is it just me?
Does anyone know of a better work-around than removing references or unloading F# projects?
Does anyone know if Microsoft is already working on fixing this? If not should this be reported to the F# team or the Visual Studio team?
Between this issue and the fact that it is still impossible to use NuGet to add an Entity Framework 6 reference to any F# project, I'm starting to get nervous about Microsoft's level of commitment to the F# language.
Not sure if this will help you but check the version of EntityFramework in your solution. I had two projects within my solution and for whatever reason, the web project had EF 6 and the class library project was EF 6.1. Once I uninstalled EF completely from the solution and reinstalled EF 6.1 on both project, the "Add new view" action started working.
I received the same error message when adding views or controllers in a C# & MVC multi-project solution, using EF 6.1 and VS2013 with Update 3. The problem was because the nuget "packages" folder was marked as read only, because it was checked into source control. I checked the entire folder out, making it editable, and it started working fine, allowing me to scaffold straight from VS.
I also received the error message in a web.api project because I forgot to add the Entity Framework connection string to the web.config (it was using Areas and EF was looking in the Area web.config, not the web.config in the root).

Resources