简体   繁体   中英

Scaffolding Files for Razor Pages in Visual Studio

First off, I know that Stack Overflow has been asking many questions regarding scaffolding in Visual Studio and I'm sure I've read every one of them. So here we go. I'm trying to customize the built-in scaffolding files that visual studio 2019 uses to create pages when we using the scaffolding functionality. 下面是调用脚手架函数的例子

My first question is where are the default files located for the scaffolding. I've already found the files that live here: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\Extensions\Microsoft\Web Tools\Scaffolding for the older mvc pages and I also found this here: C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.visualstudio.web.codegenerators.mvc\2.1.7\Templates that seem to be close but no luck. So if you can tell me the location first, that's a two thumbs up.

Next part of my question is how do I bring these into a project? I have seen many different tutorials that indicate creating a CustomTemplates or Templates folder in the project, but for razor pages, I'd like to know how to do it properly.

Thank you for any leads ahead of time.

Sometimes you have to ask the question publicly to find the answer. So I did find an answer to both questions and maybe I'll save someone else hours and hours of frustration on this problem.

I did find the files in question here:

C:\Users.......nuget\packages\microsoft.visualstudio.web.codegenerators.mvc\5.0.2\Templates

Now the location is dependant on the version of .net core you are running. I'm running version 5, so this fits perfectly.

Next, I literally copied over the folders I needed from that folder to a folder in the project on the root called 'Templates'. Here's an example of what my test project looks like.

在此处输入图像描述

I grabbed the ViewGenerator folder (for example) and made changes to the list.cshtml file in the directory and the changes were replicated. Problem number two solved.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM