So I'm having some trouble creating an item template and would like some help.
What I'm trying to do:
Create a template that adds 3 files. A Class.cs and two config files in the location "./Config/Acc/Config.xml" and "./Config/Prod/Config.xml".
I've managed to create the template through the wizard and editing the resulting files, but I would like an easy method of distributing the template on my teams TFS.
From some googling it seems that I should use A VSIX project to deply this easily. Problem is that I can't get it to compile. I have 2 projects: VSIXproject and ItemTemplateProject. I've set the assembly info on VSIX project to use the ItemTemplateProject and I've modified my Class.cs, but when I compile, visual studio doesn't know how to handle the Class.cs file.
What am I doing wrong? Is there a better way of including my ItemTemplate so that anyone who pulls the repo can use it?
The template project (a project that only contains Visual Studio project templates or item templates) is only used to be able to work with templates. Its output (say [myproject].dll) is not important (the project type may be C# but it's irrelevant) and you will only distribute the .vsix file in the end.
Files (.vstemplate files and any other files) in this project are like "static" files. They will also ultimately be included into the .vsix file output during build.
So, to ensure this files (.cs or other) are "static", you must make sure they have their action set to None (for example), not Compile.
Related
I am writing an extension for our group that creates a few folders and .cshtml files. This extension will also add a few dozen code snippets. I would really like to add some of the code snippets to the files when they are created so if a user changes their snippet it will also change in the generated code. Is there any way to access/insert code snippets from an extension?
The code snippet is usually added when developing/writing codes. Looks like you want to make this process automatically, like the newly created/inserted file has already included the related codes. And it seems you also want to make the snippet changeable.
I’m not sure if your requirements are more related to the project template or the more complex Visual Studio extension. I can share you a simple sample about how to insert a normal code snippet from a normal VS extension to the developed project/file, but it is manually. So perhaps it’s not what you want but I hope this could give you some references or a little help.
Sample
1). Install related VS SDK, and workload for creating Visual Studio Extension project. Create a VSIX project in VS.
2). Right-click the project in Solution Explorer and add one new folder(named it for example Snippets), after that add a subfolder named like My snippets(you can add other subfolders to classify), in this subfolder add some .snippet files.
3). Edit the .snippet files and add some related XML codes in it. Refer to this document: Snippet template.
4). Create a new file named XXXX.pkgdef and save it in project root folder, edit it and add related codes in it for registering. For example(for C#)
[$RootKey$\Languages\CodeExpansions\CSharp\Paths]
"MySnippets"="$PackageFolder$\Snippets\XXXXXXXX"
5). Right-click the source.extension.vsixmanaifest file > View Designer > Asserts > if there is a source, select it and click Edit > Choose related things:
6). (Optional) Edit the source.extension.vsixmanaifest file > Metadata to fill the related information that you want to set, such as Description, License Tags…
7). Hit F5 to debug and an Experimental instance of VS will launch, check the code snippet feature there.
Related documents threads/blog: Shipping Visual Studio snippets in an extension.
I have some common code between two project solutions, and I would like to link a source file from one solution to another. Specifically, I would like to add/link a single .cs file from a different solution to my current one.
This seems to be a good answer. However, Visual Studio Code does not have the add as link or add existing item. It only have Add Folder to Workplace. Furthermore,dotnet add and dotnet sln add only takes .csproj file, which is the whole project.
So how do I achieve this?
We generally don't share sources files because it creates all sorts of problems.
What we do is put the code in a class library and share the project (or assembly) with anything that needs it
My situation:
I have a solution A with hundreds of projects,
Some of projects are class libraries and are referenced from other projects.
Now I want to create a new solution B which will consist of subset of projects of solution A. I start by adding the first pre-existing project into this new solution B. This project is referencing couple of class libraries from solution A. Therefore it is logical that these libraries cannot be found and I cannot build. Of course I could add all the referenced projects manually into the new solution B but that would take quite a long time, considering the total amount of projects that I need to add.
Is there some built in Visual Studio feature that can take care of this on my behalf? I.e. I will be offered an opportunity to import all the referenced projects at once and the B.sln file will be updated automatically.
I also have a ReSharper extension but I couldn't find such feature in there as well.
EDIT:
Some more detail on what I am trying to achieve. A.sln has lots of application projects and literally hundreds of class libraries. I want to create a new B.sln for one particular application project from A.sln and only add the class libraries that it is referencing, directly or indirectly... But the dependencies can go up to 15 levels deep so manually removing projects from original A.sln to create B.sln is really not suitable for me as I would have to carefully consider each one of the projects that I would be manually removing from the original sln file, subsequently reviewing the csproj files to find whether the application I am interested in does not indirectly depends on them via one of its direct references.
Copy paste your current solution file and start with it. Open it in new Visual Studio Instance. Remove your projects one by one. Instead of adding new projects, removing unnecessary ones will be more easy for you. As far as I know there is no such feature in Visual Studio as you want.
Removing will be more easy since projects are already there. Do not use Visual Studio to remove project but open sln file in suitable programmers notepad. Your projects are added to sln file as below lines.
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example.Integration.App1", "..\Example.Integration\Example.Integration.App1\Example.Integration.App1.csproj", "{E3977144-AFBA-451D-894C-1F89AA008041}"
EndProject
Removing such lines will be more easy if your projects has naming convention.
The best way to port references from an existing project that I've found is to generate a template for that project.
On the File menu, click Export Template. The Export Template wizard opens.
Choose project template and move through the wizard
Click Finish. Your project is exported into a .zip file and placed in the specified output location, and, if selected, imported into Visual Studio.
Now, when you setup a new project for solution B. You'll be able to choose the project template from A and all the file structure/references are preserved.
Ref: http://msdn.microsoft.com/en-us/library/vstudio/xkh1wxd8%28v=vs.100%29.aspx
I have a simple C# project which loads external C# files at startup to be used as scripts. Unfortunately when editing any of these 'non-project' files in Visual Studio I only get the most basic of syntax highlighting, since classes and types within the project are not known in the context of this external file.
Without adding the files to my project (defeating the purpose of them being external scripts), is there any way I can define an external interface or somehow otherwise convince Visual Studio (2008) to parse the code within these files in the context of the classes in the project?
A couple of clarifications (with thanks to the early answerers)
People should be able to edit these scripts without access to my source code
People shouldn't have to set up an entire Visual Studio project to edit one source file that's likely to contain less that 10 lines of actual code.
You will always need a reference to these classes. Maybe you can add these files as a link to the project or to a new project with a reference.
Visualstudio needs some informations to accomplish that.
I would think about the Bridge Pattern and you need to add the class body in the same file
http://en.wikipedia.org/wiki/Bridge_pattern
or using mock objects- you can easily use them to provide syntax highlighting without sharing your code (the same here - all in one file):
http://en.wikipedia.org/wiki/Mock_object
You can separate the script and the assiting classes if you would allow having a project file.
I want to develop a C# template for visual studio. I need to assign a different GUID for each project generated with this template (it should remain the same for multiple builds of the same project). I believe there is already some mechanism to do that ([assembly: Guid] attribute or project guid I don't know). So what is the correct way to do that?
Navigate to the VS install directory, then drill into Common7\IDE\ProjectTemplates\CSharp\Windows\1033\ClassLibrary.zip. You'll find the template version of assemblyinfo.cs there. Copy that to your own template .zip file. Note that 1033 is English, it may a different code page on yours.
The relevant line in the file is
[assembly: Guid("$guid1$")]
The IDE replaces the parts of the file between $dollars$ with an appropriate substitution when you create a project from your template. Template parameters are documented here.