Xcode has a feature where each type of file has a template that is filled out when that type of file is created. By default, those files are located at /Developer/Library/Xcode/Templates/File Templates.
These files are used to give whatever default code you want, such as a common file header, even including things like the copyright year. I've gotten quite used to the functionality in Xcode, but I find myself missing it in Visual Studio. With VS I have to manually copy-paste the header and modify it myself for each file. Is there a way to get Visual Studio to automatically populate files (such as cpp's or .h's) with code?
EDIT: I'm trying to do this with C++.
Yes, you can use templates with macros etc in Visual Studio as well. MSDN has an article on it, and there are various blog posts on the topic too. I know they work for C# and VB - I expect C++ works in the same sort of way, but you'll need to check of course. (Apologies if this isn't the case.)
Unfortunately last time I looked it required expanding and then compressing zip files in a way that seemed a little unnecessary, but it should be doable.
Related
I believe this to be possible as I'm sure I've seen Visual Studio create .h files with #ifdef/#ifndef pre-processor directives already included before but for some reason my installation doesn't include them. I find it tedious to type them out myself, any ideas why it isn't just including those directives? It's not the express version either.
I may have changed a setting in the past without realizing it, that's a possibility, anyways thanks for the help!
I am new to Visual Studio Extensibility and want to make an addin/extension which shall do the following:
It should read all the files with a specific file extension (assume "*.ump").
It should process the text/code/whatever in the files.
It should create new Class/Code file with some code in it. [The code will be produced in step 2, just need to know how to do it?]
Yet, I have been racking my brains through extensibility, saw the single file generators .... and addins which go through ProjectItems and can detect the file extension,
BUT I HAVE NOT BEEN ABLE TO FIND a complete tutorial, guide or explanation as to how or what to do!!
Please help...
You don't want to read all files with a specific file extension in Visual C++ project nor standard Visual C# project. You may do that with hand-made MSBuild project (included in the solution).
In Visual C++ projects, there is a way to define custom tools. They are run as separate processes, so you can implement them in anything you want. Studio will ask you whether you want to define a tool (they are defined in special xml files; studio has dialog for editing them) when you add a file with extension unknown to it. In Visual C# projects, just manually write a MSBuild tasks and insert them into the project.
Do whatever you want. IIRC the generated files will have to be included in the project though. Well, for MSBuild, just tweak the project to your heart's desire, but in Visual C++ they have to.
You can combine MSBuild (csproj,vbproj) and VisualC++ projects in a single solution, so I recommend using separate.
If you ever find out you need to compile for different target where you can't use Visual Studio, you'll be glad that you have stand-alone tool you were just calling from Studio and not something that embeds in it.
For a C# project, I make use of several Visual Basic macros in Visual Studio. I was just considering that these would be of use to other developers that work on the C# project.
The macros so far include removing trailing whitespace on save, organizing using directives and removing unnecessary ones, and an override for Ctrl-M Ctrl-O that expands regions. Would it be reasonable for me to include this macro code with my C# project in Subversion?
I don't know if it's even possible for macros to be made available/work in Visual Studio just because you open a particular Solution file, and that might be too invasive since some of the macros override existing Visual Studio behavior.
These are more like "useful tools" rather than code that is part of your project. I would not put them in SVN as part of your C# project, but if you think they are useful enough to be used by other team members, you could set up another SVN project just for these types of tools. Then your other team members could use them at their desire.
I think you would have to save the macro code to a file, and then you could just check the file into SVN. Whenever you changed the macro code, you could just keep SVN up to date with the latest macro code.
Go To definition in Visual studio 2005 works only for files that are in my project. It never works for files that are included in external libraries like mfc. When I say Go To Definition for mfc function it always shows me the header file . Is this expected behavior?
And also how does this whole thing Go To Definition work?
Thanks
I'd make the small investment required in Visual Assist. Besides all the great features it offers, it has the Alt+G command which works way better than the Visual Studio go to definition :)
For the MFC source files (at least the Feature Pack ones) I learned to find out what folder are they in (usually at C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\src\mfc) and add that folder to the Find in Files dialog.
It's not as direct as Go to Definition, and you may have to browse among the find results, but it works...
Note: I second #flippy's answer of Visual Assist, it's really great.
External libraries are references to their compiled DLLs rather than the source when referencing your own projects.
The idea is that you don't need any more than the interface to external classes, but, if you would like to see the internals of DLLs you can use a tool such as Reflector.
Yes only the interfaces for MFC will be given in header file.Unless it is implemented with Template you will not be able to access the actual definition.The dlls have implementation for those interfaces.
Well if you think about it logically, as far as visual studio knows the only definition of the MFC object that is available is the definition it sees in the associated MFC header file, so unless you actually have the entire source for MFC it won't be able to look anywhere else.
The way that intellisense/go to definition works is via a file that is created when you compile the application. It stores a mapping between variables/functions and where they are declared (or could potentially be declared, in polymorphic situations), and when you right click to say "go to definition" it references that file.
Yes this is the expected behavior. Only the declarations (header files) of the MFC code are available on your box and hence that is the only location that it can take you to.
What are you expecting it to show?
I've updated my default templates in Visual Studio for classes, interfaces, code files, etc. I removed the default namespaces and added a copyright header blurb.
Is there a way to use a variable or something in the template so I don't have to zip/unzip and re-run the vs installer to change the copyright header? (I'm a consultant, the code-owner isn't always me or my company).
Yes, you can. The documentation for this sort of thing is part of the Visual Studio SDK. There are already many variables you can use.
If you find you want to get fancy, look into the Guidance Automation Toolkit. A template using GAT can accept user input as well as information from the project and environment, can unfold one or more templates, filling in placeholders with the data gathered, and then can execute various actions against the unfolded templates, the project, or whatever.
You can get the complete example implemented here: Multi-Project Templates with Wizard: Visual Studio 2010 Sample