Visual Studio 2017 Custom Item Templates for .Net Core 2.1 - .net-core

Following the instructions at this doc, I
Created a new "ASP.NET Core Web Application" and selected "API" from the follow on menu.
I made a small change to the provided "ValuesController.cs", then
clicked Project > Export Template.
Selected "Item template", clicked next
Selected "ValuesController.cs" from the controllers folder, clicked next.
Didn't check any dependencies, clicked next
Named it "MyControllerTemplate" and didn't add any icons. clicked finish
After all that, I ended up with "MyControllerTemplate.zip" in two places:
Visual Studio 2017 > My Exported Templates
Visual Studio 2017 > Templates > ItemTemplates
According to the doc, that should have been enough. After closing and reopening VS2017, I go to add a new item, and my installed choices are limited to Xamarin.Forms and ASP.NET Core, neither of which have my newly created template.
I also tried it again after extracting the zip file in both places.
Based on another stack overflow, I also tried changing <ProjectType>CSharp</ProjectType> to <ProjectType>DNX</ProjectType> in the .vstemplate file.
and adding
<TemplateGroupID>SharedDotNetAndDotNetWeb</TemplateGroupID>
as well as <TemplateGroupID>DotNetWeb</TemplateGroupID>
None of this has made the template visible to me.
Is there something else I need to do, or a step I am messing up?
Edit 1: Tried moving the zip file and extracted files into the Visual C# folder under ItemTemplates, neither worked.

My solution was extracting the zip file, editing the .vstemplate file to add
<TemplateGroupID>AspNetCore</TemplateGroupID> to the <TemplateData> section,
and leaving <ProjectType>CSharp</ProjectType> alone

Related

How Use Shift With F2 in Vs2019

I updated Visual Studio 2019, but I can't use shift+F2 to create new folders and files.
I tried different methods but it didn't work. How is it work?
Thanks.
Not really aware that shift F2 ever worked in Visual Studio?
You can certainly highlight a object in the project exploer and hit f2 to re-name.
but, to add a folder, web page, files etc?
Then simple right click on the project like this:
So, right click on above, then choose add, and you get this:
From above, you can add new web pages, new folders, and even existing "items" (existing files).
So, I never used shift F2 - can't recall if it ever was used or worked.
but, you can as noted highlight any object in the project explorer and hit f2.
you need to install this extension to visual studio 2019:
AddNewFile Extension
After the install, you'll be able to press shift+ F2 to add new files of any type and folders with subfolders.
working extension

SpecFlow Inserting New feature not working

I just have downloaded SpecFlow test project from bitbucket repository. Its working fine. Now I want to Add more features to it. It doesn't Automatically create feature cs file. and also test not appearing in test Explorer.
To Add a new Feature file
Right Click on your folder that you want to contain your feature files in the Solution Explorer.
Click add => New Item
In the Search box on the top right Type "Feature", an option for "Specflow Feature File" should show up. Rename the file how you like and click add.
To get the Feature files To display in the Test explorer try cleaning the solution and rebuilding. If this doesn't work we need
more info.

ASP.NET - copy existing project into solution - but cannot "Start Debugging" on any .ASPX?

In VS2015 I had an existing solution with one project ("projA").
Then, from another solution, I copied the files which make up four other projects to sit in the same directory as "projA".
I then opened the solution which has "projA" in it and used the "Add Existing Project" facility to add the four other projects.
The solution builds and everything looks happy.
However if, using Solution Explorer, I
go into one of the newly added projects (say 'projB')
select Foo.aspx from within 'projB' and
select 'Start Debugging'
then what I get served to the browser is not Foo.aspx from 'projB' but the 'Index.cshtml' from 'projA'.
I'm guessing (and 'guessing' is the word) this is related to the fact that 'projA' is marked as the startup project and 'projB' isn't ? So I read here https://msdn.microsoft.com/en-us/library/a1awth7y.aspx that I can have multiple startup projects but I'm not really clear on whether there's some negative aspect to that ? Would it make 'projB' visible in a way it currently isn't ?
Or maybe I've got all that wrong and there's some other reason for this ?
I think you can set the behavior you want from the solution property page. So go to the solution property page then common properties then Startup project and select Current selection so that when you select a document from a project it will be the startup project.

How edit code template ASP MVC 4 CRUD Generator?

I want to alter the default code genaration of MVC CRUD ASP . NET.
Visual Studio.It generates pages of "Edit.cshtml/Insert.cshtml/Delete.cshtml"
I want to translate "Edit" to "Alterar" - "Insert" to "Inserir", and I would like that the razor file to be called "Alterar.cshtml" instead of "Edit.cshtml"
How can I do that?
Is it possible?
Yes, you can.
Based on this excellent blogpost by Scott Hanselman I changed the default template in a few steps. The difference between Scott's approach and mine is that he apparently made it in a way that keeps the global default but gives him a separate generator for each project. Since I didn't get it working immediately, I opted to instead just change the global template.
Go to C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ItemTemplates\CSharp\Web\MVC 4\CodeTemplates\AddController (some parts of the URI may vary in your situation
Optionally: grant yourselves write privileges on Controller.tt
Open Controller.tt in an editor of your choice and change what you want to change. Note that these are T4 templates so you have a wide variety of tools to your disposition if you want to do more advanced stuff.
Create a new ASP.NET MVC project
Go to the "Controllers" folder and add a new controller (not an api controller)
You don't have to change anything to get a differently named view: the view, including the file in which it is stored, is generated based on the name of the action method that creates it. If you generate the view from Alterar then the popup window will present you with the name "Alterar" for the file.

Designer files not nesting correctly, messing up intellisense in Visual Studio

Greetings.
I've got a web site project loaded into Visual Studio 2008. The .designer files for all of my ascx controls are not nested under the control in solution explorer, and when I reference something in that control in the code behind, I don't get intellisense.
I've checked the csproj xml file, and the 'compile' elements appear to be the same as those in my other projects where this is working correctly. An example looks like this:
<Compile Include="Default.aspx.cs">
<DependentUpon>Default.aspx</DependentUpon>
<SubType>ASPXCodeBehind</SubType>
</Compile>
<Compile Include="Default.aspx.designer.cs">
<DependentUpon>Default.aspx</DependentUpon>
</Compile>
I've tried playing with the project file, using the Website\Nest Related Files menu command, and everything else that I can think of. Any ideas?
UPDATE
Note that I'm trying to nest files that should be nested already.
This is a response to my own previous post. Got MS Tech Support to straighten it out. On my .aspx pages changing line one in 2 places solved the issue for me.
In the line in each .aspx file in your project that starts "<%Page Language" change "Codebehind=" to "Codefile=", and in your "Inherits=" property if it's set up as ProjectName.FileName then remove the "ProjectName.".
For example if you had a Project named "TestApp" and a file inside it called "NewFunctionalityTest.aspx" change
Inherits="TestApp.NewFunctionalityTest"
to
Inherits="NewFunctionalityTest"
in the first line.
To nest resx files you
Add Existing Item. Add resource and designer files to the project.
Select all resource files (Not Designer files) that are not nested.
Select Properties and change the Custom Tool to PublicResXFileCodeGenerator
Should work
Made sure both partial files are the same namespace and class name? Might also try to remove them and add both files back at the same time.
I ran across this macro a while back to do exactly what you're looking for. The author even posted a video of how to use it. I have never tried it though, so I can't vouch for it.
I don't know if the OP ever fixed his issue, but something very similar is happening to me. The designer.vb files aren't nesting, Intellisense isn't working, etc... The main difference is that I'm not using ascx, I'm using straight up .aspx pages with .vb codebehinds. It appears as though all the controls placed on the aspx page do not appear to VS as declared when I go to manipulate said controls in the codebehind. I get an error list hundreds deep from code I wrote months ago (having no problems with at the time), most of them saying "Name 'objectname' is not declared" where 'objectname' is a textbox, or dropdown menu from the associated aspx page. To answer Vishal's questions...
Can you share whether this happens everytime you create a new project or is it for a specific project...?
It's happening to one project. I have multiple other applications in VS2008 showing no problems.
Did you try compiling the project?
Yes, when I compile it lists out all the build errors that show up in the ErrorList aborts, and kicks over to the ErrorList.
Does intellisense come back after compiling
No.
A little more information on this project: It's a converted VS 2003 project. These problems did not start immediately after conversion from 2003. The conversion happened months ago and I made numerous revisions to the web app since then. There's currently a version with those revisions on a test server to show off new functionality to the client. This problem only cropped up 3 business days ago when I went in to make a few formatting changes to the aspx page. I never got a chance to make those changes however because as soon as I opened the project I got the error list. This issue is affecting every aspx page I have in the project.
I do not think the nesting is an issue for you, seeing nested files is just a eye candy although depends upon matters...
Not getting intellisense is not really a factor of nesting but rather something to do with the way references are hooked up for your project... Can you share whether this happens everytime you create a new project or is it for a specific project...?
Did you try compiling the project? Does intellisense come back after compiling... Typically for WAP projects if for somereason intellisense does not become available it should come after you compile the project...
Let me know if are still facing this issues...

Resources