I have up to now been using a macro to convert "This sort of text" to This_sort_of_text.
This is very useful for typing test class names.
(Details here: http://blogs.msdn.com/b/elee/archive/2010/02/28/my-bdd-naming-macro.aspx)
Unfortunately Visual Studio 11 (2012) does not support macros any more.
Can the same be done with resharper?
If not i might look into creating a VS Extension... unless anyone knows one exists.
You can develop a ReSharper plugin for it, it could be easier than a VS extension. See here for more info Resharper API for selected text and remote code generation . You can use document.ReplaceText method to make modifications.
Related
I have just installed the resharper extension on my Visual Studio and when I type the following:
public string value {get; set;}
Resharper adds the braces around get;set; and highlights the last }. Then when I type }, it adds another } in the line below it?
Why is this happening?
I know this is a pretty old topic, but I just ran across this myself after reinstalling reshaper 10 for VS2015 - it's maddening...I cant believe this bug has been around this long.
To correct it:
Remove the checkbox next to "Auto Format on Closing Brace" - this will allow overtyping on the ending brace in properties without adding the additional brace.
Options Dialog for Resharper
This might not be ReSharper, but actually Visual Studio. Since 2013, Visual Studio supports automatic brace completion, but it doesn't play well with that of ReSharper (which is preferable, since it supports overtyping - typing another } will replace an existing }).
Best thing you can do is to turn off Visual Studio's automatic brace completion, by going to Tools - Options - Text Editor - C# and unchecking "Automatic brace completion":
EDIT: I just noticed you tagged this as visual-studio-2012, which doesn't support this out of the box. Do you have the Productivity Power Tools extension installed as well?
I have put XML comments in a C++ source file that IntelliSense appears to pick up and use. It creates a project xml file, and IntelliSense works when I edit the original source file (showing me comments when I'm selecting a member function or entering parameters).
But, when I go to the Class Wizard in Visual Studio 2012 Express, the entered descriptions don't appear anywhere (on the methods, for example, down at the bottom of the dialog, where description remains sadly empty). For that matter, IntelliSense only works in the original file(s), so when using a call in a separate file, none of my XML comments get picked up. Why does it only work in the original source file? What have I neglected to do?
I don't think you've neglected to do anything, unfortunately.
The Class Wizard was built long before Visual Studio supported XML doc comments, so it's more likely that no one remembered/cared to go back add support for them to the Class Wizard dialog.
In my experience, although it sounds like you've had slightly better luck, XML doc comments are not particularly well supported when using C++. For example, VS 2012 was the first version to support them in IntelliSense (and even that is incomplete). You get nothing in VS 2010 and earlier versions, despite the fact that they'll happily output a project XML file. That pathetic lack of support, combined with the angle bracket tax, drove me to switch to Doxygen when writing C++ code.
I recently installed Visual Studio on a laptop and the syntax highlight fails to change Classes colors.
I tried exporting and importing the full, complete set of settings and it is still looking like that.
EDIT
I tried those websites with schemes and decided to try one, the Humane scheme, and this is how the sample code looks in my laptop after installing those settings:
However, this is how it is supposed to look:
Note the lack of highlight in class names.
What could it be causing this?
I'm starting to think that's another setting at another place which causes this.
Finally, it worked by resetting user data, running this from the Visual Studio Command Prompt
devenv /Resetuserdata
Found the hint here:
https://stackoverflow.com/a/11988265/1213246
Changin syntax highlight could be done through the menu Tools - Options - Environment - Font & Colors. It's a try and test approach that is not much improved from earlier versions of Visual Studio.
Fortunately, today there are entire sites with themes that simply need to be choosen and installed
I suggest you to visit http://studiostyl.es/ where you can find thousands themes or, for more generic go to http://www.hanselman.com/blog/VisualStudioProgrammerThemesGallery.aspx
I use macros extensively for ViewModel properties in XAML development. I use them even more in WCF to generate Message and DataContract properties.
To my disappointment, the macros I've built aren't going to be usable in Visual Studio 2012.
An example of what I'm talking about, for a VM, I would enter something like this.
int id;
string name;
Select both lines, run a macro and end up with
private int _id;
private string _name;
public int Id
{
get {return _id;}
set
{
if(_id != value)
{
_id = value;
RaisePropertyChanged("Id");
}
}
public string Name
{
if(_name != value)
{
_name = value;
RaisePropertyChanged("Name");
}
}
I'm looking for ideas of other solutions deal with losing macros.
The simplest alternative to macros is creating add-ins. I know, I know, I wasn't excited about it either, but it's actually surprisingly easy. There are three simple parts to it:
Create the macro project, stepping through a wizard UI.
Write your code.
Copy the macro's .addin and .dll files to your Visual Studio Addins directory.
Let's take a simple macro I wrote to show the Start Page after closing a solution and turn it into an add-in.
Create the macro project
Run VS 2012 and create a new project.
Go to Templates > Other Project Types > Extensibility and select Visual Studio Add-in.
Give it a name, such as ShowStartPage.
Click OK. This brings up the Add-in Wizard.
Step through the wizard, choosing:
Programming language: we'll use C#
Application host: VS 2012 should be selected
Name and description for your add-in
On the add-in options page, checkmark only the second option ("I would like my Add-in to load when the host application starts")
Skip past the About Box stuff for now, and click Finish.
Now you have an add-in project. Here's what you do with it:
Write the code
Open the Connect.cs file. (It might already be open. Some of the "DTE" stuff should look familiar.)
Add this code at class level:
SolutionEvents solutionEvents;
Add this code to the OnConnection method, right after the _addInInstance = (AddIn)addInInst; line:
solutionEvents = _applicationObject.Events.SolutionEvents;
solutionEvents.AfterClosing += () =>
{
_applicationObject.ExecuteCommand("View.StartPage");
};
Hit the "Run" button to test your code. A new instance of Visual Studio 2012 starts up, with your add-in loaded. Now test the add-in and make sure it works. (Open a solution, then close it; the Start Page should return when you do.)
Deploy it
Once the add-in works, to use it regularly with Visual Studio 2012, you only need to deploy two files:
ShowStartPage.AddIn (from your main project directory)
ShowStartPage.dll (from your project's build directory; e.g. bin\Debug or bin\Release)
Put those two files in your VS 2012 add-ins directory, probably located here:
C:\Users\[your user name]\Documents\Visual Studio 2012\Addins
Then exit and restart Visual Studio, and you should see your add-in working. You should also see it listed when you go to Tools > Add-in Manager.
While this is a bit more of a nuisance than just opening the macro editor and sticking your macro code in there, it does have the advantage that you can use any language you want, instead of being stuck with the somewhat flaky VB-like editor in past versions of Visual Studio.
The Visual Commander extension (developed by me) is an alternative to macros in Visual Studio 2012/2013/2015. You can even reuse your existing Visual Studio macros code in new VB commands.
I'll stick to cutting the text into Notepad++ and using macros there, then pasting back. It is a shame the feature isn't in Visual Studio 2012 any more...
There is an add-in, VSScript, for Visual Studio which replaces missing macros functionality. Although it does not use Visual Basic, but the Lua scripting language, you might want to try it out.
There is a recorder, macro code editor window with IntelliSense, and a simple debugger. The add-in also supports earlier versions of Visual Studio, so if you prefer the Lua language rather than Visual Basic, you can use it instead original Visual Studio macros.
I was very sad to see Macros go too. You can get close with substitutions using the regular expression search and replace inside of Visual Studio 2012. In your case:
Find:
(.*) (.*);
Replace with:
private $1 _$2;\npublic $1 $2\n{\n get {return _$2;}\n set\n {\n if(_$2 = value;\n RaisePropertyChanged("$2");\n }\n}\n
That will get you everything except capitalization of property names which Macros would be better for.
But one advantage of the regular expression approach is when the input isn't as simple (e.g. database table DDL statements).
Here are a couple of useful links from MSDN:
Substitutions in Regular Expressions
Using Regular Expressions in Visual Studio
I use Notepad++ with regular expressions like this:
Find:
public (.\*) (.)(.*) \\{ get; set; \\}
Replace:
private \1 \l(\2)\3; \r\n public \1 \2\3 \\{ get \\{ return \l(\2)\3; \\} \r\n set \\{ \l(\2)\3 = value; OnPropertyChanged\(para => this\.\2\3\); \\}\\}
Check out http://devexpress.com/coderush
The templates feature does pretty much what you want.
There is a free "Express" version too.
Visual Studio 2012's lack of macros was getting me down, as I have a few that I use literally all the time to insert standard little bits of text with a single keypress. So I wrote a very simple scripts extensibility package, VSScripts, which allows manipulation of the current selection from a command-line program.
This doesn't claim to be some all-encompassing full replacement for the old macro system, and it doesn't provide keyboard macros, but it does make it possible to recreate many types of text manipulation macro.
Here's what I did to keep my macro functionality...
Download and install the Visual Studio 2012 SDK here (it contains the "Visual Studio Package" template)
New project -> Installed.Templates.Visual C#.Extensibility.Visual Studio Package
Wizard page 1 of 7
language = C#
gen new key is fine, or use another if you have one
wizard page 3 of 7
check "menu command"
Wizard page 7 of 7
uncheck both integration and unit test project options
Click finish
In the .cs file:
using EnvDTE;
using EnvDTE80;
...
private void MenuItemCallback(object sender, EventArgs e)
{
MenuCommand cmd = sender as MenuCommand;
// This should start to look like familiar macro code...
EnvDTE80.DTE2 dte2 = Package.GetGlobalService(typeof(EnvDTE.DTE)) as DTE2;
TextSelection selection = (TextSelection)dte2.ActiveDocument.Selection;
dte2.UndoContext.Open("macro command replacement");
selection.Text = "inserted from macro replacement";
selection.NewLine(1);
dte2.UndoContext.Close();
...
Run the project. A new Visual Studio instance will start with the package loaded.
Find your command as the first entry at the top of the Tools menu. Click it to see if it works.
To install for real, go to your bin\debug(/release) directory and double-click on the .vsix file
It should be installed for the next time you run
Go to menu Tools -> Options... -> environment.keyboard and map a keystroke to your tool
Mapping theme : Visual C# 2005
Command : Tool.yourFunctionName (functions defined in the .vsct file)
If you want more than one command, you will need to add menu id's in the PkgCmdID.cs, Guids in the Guids.cs, layouts in the .vsct and a function in the *package.cs (and button(MenuCommand) in the Initialize function) for each one. It can all be done in the same project.
I used this project to create several new 'tools' with my old macro code, then mapped my keys to them. It's a lot more work (and headaches) up front, but doesn't have the lag time that macros had.
There is probably a way to do this without having it take up tool menus. I started looking at this last night and finally got it to work, so I'm done with it for now (at least until Microsoft decides to drop this too).
Personally I like this one - the Visual Commander extension lets you automate repetitive tasks in Visual Studio.
I'm a long time Eclipse user trying to learn to Visual Studio. I know that Eclipse had Code Templates that would allow you to build classes with certain comments and formatting already added for a class.
For example:
Auto placing the copyright for the code at the top of the file
Who created the file
Predefined Comments,
etc...
Does Visual Studio 2005 have any functionality like this?
It depends. Visual Studio has a built-in code snippets manager that lets you do things like this to at least a degree (i.e., if you insert a code snippet, it'll be formatted as the snippet specifies, but if you write the same code manually, it won't). Also note that there are limitations on the languages with which you can use code snippets.
Outside of that, most of the major add-ins for VS (e.g., Visual Assist-X) provide their own ability to store and insert bits of code, formatted as you specify. Most of these provide at least some features missing from the built-in snippets manager such as working with other languages or being easier to access (along with quite a few other things -- IMO, VS borders on completely unusable without VA-X).
I would recommend looking at item and project templates in Visual Studio, which sound like what you're looking for. But, in your particular case (C++ development), it doesn't look like this is available to you.
The following MSDN article refers to VS templates, and mentions that for Visual C++ projects, that the template architecture isn't supported. Instead, there's information on creating custom wizards for your project and classes, which may give you the flexibility that you need. Sounds like it'll do what you want it to do, but it's much more work than it would be if you could use an item template for including basic comment structure for a default class file.
http://msdn.microsoft.com/en-us/library/6db0hwky%28VS.80%29.aspx