Create a Visual Studio project template VSTemplate key points Summary

Source: Internet
Author: User

From:http://www.cnblogs.com/stickman/p/3454719.html

After many experiments, we finally made a perfect one. VSIX Project template installation package, which encountered a lot of problems and setbacks, the google/baidu/self-groping. Finally solve all the problems.

We will summarize the following notes

About. vstemplate

1. The. vstemplate and other project files can be generated directly from the export template to be the master of the template! It is recommended that a copy of the Csprj file be copied. vstemplate The template project file referenced inside.

2.targetfilename/targetfoldername can be modified or even replaced as required, but the original file name and directory name must exist

3./project[@TargetFileName] csproj generated by the project file, the syntax must be correct, otherwise not only can not build the project, error prompts are also easy to let people mistakenly think that is. vstemplate error

4. About <customparameters> must be placed before </Project>,</templatecontent> (the schema defines the order)

5. Project exported through the menu bar, generated in%userprofile%\documents\visual Studio 2012\templates\my exported templates\, when compressing the project file as Zip, The root directory must contain. vstemplate, otherwise it cannot appear in the VS Template Project selection interface

After 6.zip template project file, need to put%userprofile%\documents\visual Studio 2012\templates\projecttemplates side can be identified by vs.

7. The AssemblyInfo.cs file should also be moved out of the properties directory and modified in. VSTemplate as follows

 <ProjectItemReplaceParameters= "true"TargetFileName= "Properties\assemblyinfo.cs">AssemblyInfo.cs</ProjectItem>

8.vstemplate Project. cs file, because the $ variable is replaced by $, normal generation will prompt a large number of error messages. Therefore, you need to set the file properties-build action for all. CS to none.

Or, in the SLN solution file, set the item as not generated in the configuration properties (this method is not recommended)

9. You can attach a. bat batch file. The content is as follows

CD %1 "C:\Program FILES\HAOZIP\HAOZIPC" a templateproject.zip *.  move/y Templateproject.zip. \template.vsix\projecttemplates

Note: When the build project executes a batch file, the project directory is passed into the bat file as the parameter%1

BAT Line 1: Enter the project directory, convenient line2 compression command to compress this directory and subdirectory file, reason reference 5th. Point

BAT Line 2: Compression commands, using compression software with command lines, such as Rar,haozip. But Haozip is very strange, my home machine is installed in program files, and the company's machine is Program Files (x86). But both machine operating systems are x64

BAT Line 3: The above is where you move to the VSIX directory (recommended to use IWizard-generated DLLs) and can actually be moved to%USERPROFILE%\Documents\Visual Studio 2012\templates\ Projecttemplates Direct use (when no iwizard)

About IWizard

IWizard is also a very troublesome thing, because rarely used to register to the GAC signed the project, so then also walked a lot of long way

1. Need to quote EnvDTE and Microsoft.VisualStudio.TemplateWizardInterface

2. As long as you implement the interface method RunStarted, the Shouldaddprojectitem method returns True, all other methods are left blank

3. You can create a WinForm to enter parameters, and then runstarted inside the WinForm, and ShowDialog ();

4. The parameter replacementsdictionary can be accessed or modified, where a new substitution variable is added, or the value of the default substitution variable is read

5. The project needs to "sign--sign the Assembly", the generated key file must be with a password, or cannot be added to the GAC

When a project is copied to another machine, it will be compiled with errors associated with the certificate file. Just reenter the password at the change password at this point

6.GAC registration may seem simple, but there is a place for attention. First run the VS tool command prompt with an administrator, and then command parameters need to be noted

   Register              gacutil/i project name. dll       unload              gacutil/u project name     You can't take a DLL here.       GACUTIL/LR project name     cannot take DLL here

7. When using a VSIX project, you can omit the 6th.

About VSIX Projects

You can choose to create a VSIX project if you want to not register the GAC, and you can distribute it to others with great dazzle.

But if it's a small team, I'd recommend registering the GAC and then setting the template directory in VS to a shared directory to access the zip file generated by VSTemplate.

1. You need to download the Visual Studio 20XX SDK before you install it to create a VSIX projct (under the extensibility section)

2. Visual editing source.extension.vsixmanifest, the key is to create the corresponding item in the Asset column

A. For IWizard-generated DLLs, note that you want to refer to the project that contains the IWizard

Type:Microsoft.VisualStudio.Assembly

Embed in this folder fill in "Assemblies"

B. For VSTemplate projects

Type:Microsoft.VisualStudio.ProjectTemplate

Source: You can select File on System and the file will be automatically copied to the Projecttemplates directory. Therefore, the "about. VSTemplate" 9th describes the batch move location, which should be the path

If you choose A Project in the current solution, be aware of the following.

3. After you select A Project in the current solution, if you are prompted at compile time, "there is no target" Templateprojectoutputgroup "in the project, then presumably your project is changed from the template exported from the menu bar. If you are new-extensibility--c# Template Project, this error will not occur.

The problem can be found in Google,baidu, but there is no definitive solution to the problem. Finally, after careful comparison of the two sets of csprj files, I found that I needed to add the following two items

A. Add the following item to <PropertyGroup>...</PropertyGroup>

        <VstoolspathCondition= "' $ (vstoolspath) ' = = '">$ (MSBuildExtensionsPath32) \microsoft\visualstudio\v$ (visualstudioversion)</Vstoolspath>

B. Find <import project= "$ (MSBuildToolsPath) \microsoft.csharp.targets"/> Add below

<  import  project  = "$ (vstoolspath) \ Vssdk\microsoft.vssdk.targets "  Condition  = "' $ (vstoolspath) '! = '"   />  

And a must precede B.

4. After installing the VSIX, if you do not see it in the new project, close all the VS IDE and reboot to display.

The update also needs to be uninstalled--and then installed--and then restarted.

This is why it is recommended to use the settings template directory as a shared directory in a small team. Otherwise, it's too much trouble.

Create a Visual Studio project template VSTemplate key points Summary

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.