Creating a Visual Studio 2010 Item Template with multiple folders and files - visual-studio-2010

I've been reading info on this the past few days and though I've made some progress, I'm still a bit lost.
I have created a collection of classes, files, and folders that together I want to join together as a Visual Studio Item Template.
Think of it as a "module".
The idea is that they add this "Module Item Template" and Visual Studio will insert the folders and files and rename them accordingly.
This is not a PROJECT template it is an ITEM TEMPLATE, because it needs to be added to an already existing project they are working on, within that project (not as a separate one).
By using the Visual Studio 2010 SP1 SDK Item Template Template, I've ALMOST got it.
The problem is that when I use the $safeitemname$ I get different names in each class.
I was hoping that when they add the item, and name it say "MyModule", the value $safeitemname$ would be "MyModule".
this isn't happening. Instead, each generated class file gets a different value for $safeitemname$ that matches the generated file name.
So for example if I have a MyModuleConfig.cs class, and I have another class file setup like this:
public class $safeitemname$Config
{
}
instead of getting the Item name that the user entered "MyModule" together with config, the class gets named "MyModuleConfigConfig".
How can I tell it to only use the original name that the user entered when they created the module in the Add Item dialog using the template?

okay literally seconds after posting this I discovered that I should be using the $fileinputname$ instead!
this appears to be exactly what I wanted, thanks, self!

Related

Which is the most advantageous strategy for creating a tweaked Visual Studio Project Template?

I'm appealing to the wisdom of the crowd here, trying, in this case, to avoid the code less traveled.
I created a Visual Studio project template, but now find there are a couple of things I can/should add to it, and one or two things I need to modify.
What is the "received" way, or "preferred method" of doing this: modifying the existing template directly, or opening a project using the existing template, and then saving that template-based project, after modification, as a template, perhaps overwriting the previous one (if that's even possible/allowed by the VS "ecosystem")?
I copied the extracted contents of the zipped template from C:\Users\clayshan\Documents\Visual Studio 2010\Templates\ProjectTemplates\Visual C#\folder_name\template_name.zip to another location.
Does it make the most sense to open that project, modify, and save as a template, or to simply create a new project from the existing template, and then save that "new and improved" project as a template?
RUNNING COMMENTARY
When I open the extracted template as a project, I get a warning, "Load of property 'RootNamespace' failed. The string for the root namespace must be a valid identifier." I don't know if this is to be expected in this scenario, or if I should be slightly scared.
Another funky (as in "gives me the fantods", not as in the Troglodyte song) thing is that a template won't compile, as it's got those placeholder namespace names.
I edited the existing, zipped, copied it over to the village where the VS templates live and...now when I go to start a new project, there are two identical-looking templates there: the old, and the new. The question is, which is which? It's kind of annoying having to open them to see...
The final (hopefully) weird thing about the process is that, even though I added a "Site ULR" property to the template, on creating a new project from the template, that assignment reverts to blank.

Custom Item Template Group

I'm building out custom item templates to work with our internal platform. Is it possible to have these templates appear in their own group say "MyGroup" as opposed to being dropped into one of the other pre-existing groups?
Depending on how you are deploying your custom item template, I've found two ways to do this.
If you are simply deploying the .zip file, you can place it in a sub-folder in the appropriate language folder inside your ItemTemplates directory. For example:
\My Documents\Visual Studio 2010\Templates\ItemTemplates\Visual C#\MyGroup\myTemplate.zip
If you are installing your custom template as part of a VSIX file, then open up the your .vsixmanifest file in the designer in Visual Studio, go to the "Content" section (at the bottom), and remove your Item Template. Now, add it back using the "Add Content" button, and specify a "subfolder" (e.g. "MyGroup"). Now, when you install your extension, your Item Templates should show up inside a group with the same name as the specified sub-folder.

How does Visual Studio determine which item templates are available in a project?

I would like to have the Add->View... context menu item available in a project that starts out as a class library, just as it is available in a project that starts out as an MVC 4 project. I have given the .csproj file a cursory read through, but I don't see anything saying, "This is an MVC project", so how does VS know this?
I have since learnt that VS looks at the ProjectTypeGuids element in the project file, and that I must add the GUID E3E379DF-F4C6-4180-9B81-6769533ABE47 to the front of this elements value. Maybe my question is clearer now that I can say I'm trying to find out what the association is between these GUIDs and the item templates available in a project.

How to associate a Resx file to a class in Visual Studio 2010

How do I associate/"bind" an resx file to a class file in Visual Studio?
For example, when a new windows form is created, an resx file is automatically associated with it.
I am asking this as the following code doesn't open the right resource file for another .cs file I have:
ComponentResourceManager manager = new ComponentResourceManager(typeof(MyClass));
This code works fine for frmLogin from above however.
The MSDN documentation for the constructor:
Creates a ComponentResourceManager
that looks up resources in satellite
assemblies based on information from
the specified Type.
That a form has an associated .resx file is an implementation detail that's specific to forms. You cannot otherwise associate an arbitrary class with a .resx file. I assume that you actually want to use a ResourceManager here.
Do note that there's one already built-in through Properties.Resources, giving you access to resources that you added to Project + Properties, Resources tab.
Should you have lost this indenting by adding existing files to a project, you can restore the indenting for files, though I have not tried it for all file types, by using the 'DependentUpon' node in the project file.
The technique is described in more detail at Code rant: Nested files with 'DependentUpon' in Visual Studio
I found an existing answer on SO since discovering the article above, but as the question is formulated so differently I'm keeping this answer in place.

sharepoint 2010: sandboxed webpart error

I was just tryng to create a simple webpart in visual studio 2010 (for sharepoint 2010)
I created an empty sharepoint project, then added a webpart. I wrote a simple code (pasting it from a book with examples)
I Build the project, then deploy it (without errors)
Then when i go to the webpage where i want to add my webpart, i get this error when adding it:
"unhandled exception was thrown by the sandboxed code wrapper's
Execute method in the partial trust app domain:
$Resource:core,ImportErrorMessage;"
Any idea about it?
If it's needed i'll post the code of the .cs file
Thanks
i don't know why but the second try worked
i can't say exactly what went wrong the first time, but i never get the same problem now
I've figured this one out, its something to do with the manifest and features xml files that are generated along with the project.
When you start you should have a namespace like this.
ASMLab4.DisplayWebPartWithProxy.DisplayWebPartWithProxy
But for some reason in those xml files it's added as
ASMLab4.DisplayWebPartWithProxy.DisplayWebPartWithProxy.
With an extra '.' (dot).
The fix open something like notepad++ do a search through the project and at first look for
ASMLab4.DisplayWebPartWithProxy.DisplayWebPartWithProxy..
They should be in the manifest/features files. Change to a single dot so should have something like
<type name="ASMLab4.DisplayWebPartWithProxy.DisplayWebPartWithProxy.DisplayWebPartWithProxy, $SharePoint.Project.AssemblyFullName$" />
Next do a search for a single dot. There should be one in the safe list, remove the single dot. Try the deployment again - should be ok.

Resources