Razor Syntax Highlighting - asp.net

I have a fairly large ASP MVC project which I am running in visual studio 15.4.5. Whenever I view .cshtml files Visual Studio incorrectly highlights the file for example:
We are making use of compiled razor views.
The project compiles and runs correctly
What I've tried
Deleting all bin, obj & .vs folders
Running .\devenv.exe /ResetUserData
Running .\devenv.exe /UpdateConfiguration & .\devenv.exe /ClearCache

I found this question whilst trying to solve the nuisance that is the highlighting myself so thought I'd share my findings. Apparently this is the intentional behaviour as it referred to as "Razor Syntax Highlighting" and through both this post on MSDN and another question on here: How do you turn off Razor highlighting in VS 2013? I was able to determine how to turn it off on my machine.
Quote from MSDN post:
This highlighting is the built in support for Razor syntax highlighting. If you do not like it, you can open your .cshtml files in Visual Studio using the HTML editor
Screenshot of what I changed that worked for me:

Related

Visual Studio 2017, a way to easily open an included script?

I'm sorry if this question has been asked before but I couldn't find an answer so far.
Let's say I have a asp.net mvc5 project, and I have included a external script file in my cshtml file using razor.
like so:
<script src="#Url.Content("~/Scripts/Path/File.js")"></script>
is there any way to easily open that file from the include statement? Or is there a different way to include the script that would allow such functionality?
plug-ins are also welcome.
Thanks everyone.
I don't think there's such extension nor feature in Visual Studio unfortunately. There'are extension for Visual Studio Code (e.g. Open file), but not for the "big" Visual Studio.
You can try to create your own extension to do that, it shouldn't be so complicated.
Or you can try to create a feature request on UserVoice and wait if it's accepted and implemented.

Create a VS 2017 extension to add new code file

I hope someone can point me in the right direction. I have two separate piece of code that functions outside of Visual Studio.
The last step performed by the second piece of code currently creates a new c# source file. I would like to combine both pieces of code into a single VSIX extension.
Unfortunately I have never worked with VS Extensions and I am a bit lost. I have worked through various VSIX examples, but none of these create files.
Can anyone perhaps point me to a working example of how to add new source files to a project via an extension?
I have seen some examples, but they all refer to old Add-In style plugins and not VSIX.
Create a VS 2017 extension to add new code file
As we know the Visual Studio Extensions is:
Extensions are add-ons that allow you to customize and enhance your
experience in Visual Studio by adding new features or integrating
existing tools. An extension can range in all levels of complexity,
but its main purpose is to increase your productivity and cater to
your workflow.
So, the Visual Studio extension is service for Visual Studio IDE to customize and enhance your experience in Visual Studio, rather than serving a specific project.
What I suspect the Project and item templates should be helps.
Hope this helps.

Visual Studio C# ASP .NET Web Form Designer Error

Ok, so I start a new project in Visual Studio (currently updated to update 3) and choose ASP.NET Web Application (.NET Framework).
Then I choose the Empty template and to add the folders and core references for Web Forms.
Ok, great, so I add a webform to the project and then find there's a problem:
Design view or even Split view is not available for the new aspx page.
Pressing the buttons 'Design' or 'Split' do nothing and only the source is seen, which also becomes uneditable.
Now I have seen this issue before and searched and searched for an answer. But the only solution was a complete reinstall - this means a few GB download and then hours of the install program doing whatever it does (it is the slowest install for anything on any platform).
This issue seems to occur randomly, and once it occurs, it seems to be permanent, short of a complete reinstall of VS.
Is this a fault in Visual Studio that will never be fixed?
Does someone actually know how to fix this other than a complete reinstall?
Please do not suggest to try 'Open With' on the aspx file - yes I have tried every option and the original default is the correct one.
Answers from the Microsoft forum are about as helpful as giving wheels to a tomato, such as here. It has even been highlighted for Visual Studio 2008 here. Someone seems to have tried to raise the issue last year here.

Visual Studio 2015 CSS Intellisense Broken

Editing cshtml files, I'm used to getting Bootstrap intellisense, regardless of what classes I've already used in said file, like so:
Originally, I thought it was just Bootstrap intellisense, but it appears that this is affecting all CSS for my new project. I can link to the CSS files, directly reference the layout file, it doesn't matter. The Bootstrap and other CSS classes do not show, unless I've already used them in the same file:
I've tried to minimize the differences between the two projects, but to no avail. They are on different machines, in different solutions, but everything else is virtually exactly the same. Here's what I've checked/tried so far.
Delete the project, re-add it.
Remove the Bootstrap Nuget package re-add it
Remove the Bootstrap Snippet Pack, Glyphfriend, Web Essentials 2015.2 extensions, re-add them.
Delete the bin and obj folders, build, clean, rebuild, close/reopen VS, restart Windows.
Deleted this folder to allow for recreation: C:\Users\MyUserName\AppData\Local\Microsoft\VisualStudio\14.0\ComponentModelCache
Both machines are running VS 2015 Update 2.
Both projects are MVC 5.
Installed all updates possible in Nuget Package Manager
Known differences
- The machine it works on is running Windows 7, the machine it doesn't is running Windows 10.
I've run into this problem again and found a solution! I'm not sure if it's the same as the original problem I had, but here's the fix anyway.
If the solution has a SQL project (.dbproj), unload it (right click > unload project). There's some weird bug in VS2015 with Bootstrap and SQL database projects that make intellisense for Bootstrap stop working.
In order to get "Class" IntelliSense in VS 2015, try this method. It works for me as follows:
Ex: Right click on any .aspx file in "Solution Explorer" of VS then select "Open With" option then from the list select "HTML Editor" option. Now try to check.
Thanks
Ali

Visual Studio 2013 has stopped updating aspx.designer.cs files

I'm working on a large-ish web forms application and VS has stopped updating .aspx.designer.cs files in the last few days.
It seemed like the designer updates initially became flaky (sometimes update, sometimes not) then stopped updating altogether. Now I have to manually edit the designer file after adding a control to a page before I can compile.
I've searched and tried all the suggestions like switching from markup to design view and back etc - no change. The only thing that kind of works is this but even then the generated designer file often doesn't contain references to all the controls on the page. And also that only works on a per-file basis. Ideally I would like the whole project to update/generate designer files correctly again.
I've tried cleaning the solution - no change.
VS details:
Microsoft Visual Studio Professional 2013
Version 12.0.40629.00 Update 5
Microsoft .NET Framework Version 4.6.00079
Installed Version: Professional
Any suggestions appreciated - thanks.
Make sure you're not running the application/site while adding controls. I've noticed that VS will lock the designer files while in debug mode and doesn't sync up when you exit debug mode.
Also, your link is broken, doesn't point to anything so I can't see what you were referencing to.
I think what caused this was a somewhat flaky local install of the project from TFS. It compiled but still had red squiggly lines under a few namespaces at design time. Once the project references were all clean the designer files were also updating correctly.

Resources