I've created a Blazor project using .net core 3.0 preview5 and VS2019 Enterprise. I want to create .razor files, but all of my options have .cshtml extensions.
When I'm creating my project, I'm using asp.net core 3.0 and Blazor server hosted options
In VS 2019 16.3.0, adding "Razor Component" is what worked for me.
What works is:
Add, Add Class
and then change .cs to .razor before clicking [Add]
And immediately delete all the C# stuff of course.
Or you can copy/paste/rename any existing blazor component, like index.razor.
Make sure you've got the blazor extension installed.
This should then allow you to click on the Pages Directory and at the top there's an Add Razor Page option.
But I've got to admit, I tend to find it quicker to just select an existing page in the solution explorer and Ctrl-C Ctrl-V and rename it!
Note: At time of writing this is using the preview branch of Visual Studio 2019 and frameworks.
Right click on Pages-> Add->New Item...-> Razor Component
Related
I have used Visual Studio 2019 to create a Blazor server side project.
I then added Blazorise nuget to the project.
I followed the Blazorise quick start to add in the using statements and style sheets and jquery and the registrations.
Unfortunately, once I did that, the project menu (ie Home, Counter, Fetch Data) no longer works.
What am I doing wrong?
I'm using .net core 3.1 and also tried 3.0.
Thanks for any help.
I see what the issue is now.
In the documentation, some css has to be manually copied into the headers of index.html or _Host.cshtml. I inserted these at the end of the headers but it created a problem.
Instead, I should have inserted it just before site.css stylesheet and let site.css be the last statement in the header. Then, everything started working fine.
Thanks everyone!
Context
In my .NET Framework 4.x ASP.NET MVC projects, when using the Visual Studio IDE, it was possible to edit a .cshtml view, save, then press ctrl+F5 in the browser and see the change immediately.
This seems to be no longer work in ASP.NET Core applications (using Visual Studio 2019 and .NET Core 3 Preview 5).
Question
Is this feature missing in ASP.NET Core? Is this a preview issue? Or am I missing something?
This is something that is no longer enabled by default as of ASP.NET Core 3, but it can be re-enabled as documented here:
Runtime compilation is enabled using the Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation package. To enable runtime compilation, apps must:
Install the Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation NuGet package.
Update the project's Startup.ConfigureServices method to include a call to AddRazorRuntimeCompilation:
services
.AddControllersWithViews()
.AddRazorRuntimeCompilation();
I've marked Kirk's answer as accepted, but maybe this experience could be useful also.
My goal was a "quick edit (cshtml/css/js/ts) then see" iteration.
No need to add and mod anything... I discovered that .NET Core (3) and VS 2019 is so much faster, so in case if we do not want to debug in VS (which is the scenario in most cases when we are changing cshtml/css/js/ts) there is really great iteration:
Press ctrl+f5 to launch your web app (no debug) in browser
See, test (debug js/ts in Chrome)
Edit your cshtml/css/js/ts
Press ctrl+shift+b to build (fast!)
Switch to your browser and press ctrl+f5 to refresh your page (fast!)
Goto 2
I see this error message:
When I try to scaffold a controller for and empty API Controller by following these steps:
Right-click on folder
> Add
> Controller...
> Add Scaffold -> API Controller - Empty
> Click Add
Specifications:
Windows 10 Enterprise
Visual Studio Professional 2017 15.6.4
Microsoft .NET Framework 4.7.02556
.NET Core 2.0
Web API ASP.NET Core Web Application
---Edit---
I can't replicate the problem now. One of the suggestions given by #chriss-pratt must have worked (Thank You!) While doing a tutorial, I came across the section to add scaffold tooling and perform initial migration. In case you experience this and the below doesn't work, this part of the tutorial my be promising (if you decide to stick with scaffolding that is).
ASP.NET Core doesn't strictly have an ApiController class. ASP.NET Core doesn't have separate MVC and Web Api components. Everything is just Controller. ApiController is available through a separate "shim" NuGet package, but that's only to make migrating old ASP.NET Web Api code easier. You shouldn't be using it for any new development.
That said, the problem you're having here is with the scaffold. It might be due to the fact that you're trying to scaffold ApiController rather than just Controller. You haven't give any information about what version of Visual Studio you're using or what version of ASP.NET Core.
Try the simple stuff like closing and restarting Visual Studio. If it persists, you can try repairing Visual Studio. Hit the windows key and begin typing "Visual Studio Installer". Open that when it shows up. Below your installed copy of Visual Studio in the list, there will be a drop down menu that looks like three dots stacked on top of each other. There's an option there to "Repair". Start the process and go grab a cup of coffee. It essentially reinstalls Visual Studio, so it'll likely take a while.
All that said, honestly, your best bet is to just don't worry about it. Scaffolding is all but useless anyways. Especially with ASP.NET Core, all you get is a class, which you can easily create yourself. A controller is merely a class that inherits from Controller. Add a new class in your Controllers directory, name it WhateverController and then add : Controller after the name in the code. Then, just start adding your actions and such as normal.
I'm trying to install some custom made project templates for asp.net MVC4, however my Visual Studio 2012 Premium won't show the new templates. The templates are installed by a .VISX file like this one: http://www.asp.net/single-page-application/overview/templates/hottowel-template
Visual Studio is showing this file as an "Enabled" and "Installed" Extension, but when I try to create a new ASP.NET MVC4 project it is not showing those templates as an option like shown in this image:
I'm just seeing the regular options and it is not showing me the Hot-Towel template or any other single page application template. Could you please tell me how to fix this if one of you guys knows.
I fixed this by installing ASP.Net Web Tools Update Pack Fall 2012:
http://www.asp.net/vnext
I decided to give the answer to my own question for helping others with the same question.
I would like to change a loaded Existing Web Site in visual studio (2012) in my solution to a MVC4 project web application ! Actually, the loaded web site (from local IIS) is a real MVC application (so I'm not asking about some conversion ) , but visual studio is not recognize it like this !
With the existing solution, visual studio menus act like I have a webform application :
I can't add Controller neither Views or other MVC specific items !
So how can I change the project to MVC ?
Thank you !
I added this to my .csproj and now I have the 'Add->View' in my context when right-clicking my 'Views' folder. Hope this helps.
<ProjectTypeGuids>{E3E379DF-F4C6-4180-9B81-6769533ABE47};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>