51

XAML開発では、ViewModel プロパティにマクロを広く使用しています。Message および DataContract プロパティを生成するために、 WCFでそれらをさらに使用します。

残念ながら、作成したマクロは Visual Studio 2012 では使用できません。

私が話していることの例として、VM の場合、次のように入力します。

int id;
string name;

両方の行を選択し、マクロを実行すると、

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");
   }
}

マクロを失うことに対処する他のソリューションのアイデアを探しています。

4

10 に答える 10

65

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:

  1. Create the macro project, stepping through a wizard UI.
  2. Write your code.
  3. 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.

于 2012-09-12T19:28:56.707 に答える
12

テキストをメモ帳++に切り取り、そこでマクロを使用してから貼り付けます。この機能が Visual Studio 2012 にないのは残念です...

于 2012-11-01T17:31:34.170 に答える
12

Visual Commander拡張機能(私が開発) は、Visual Studio 2012/2013/2015 のマクロに代わるものです。新しい VB コマンドで既存の Visual Studio マクロ コードを再利用することもできます。

于 2013-09-19T07:10:17.017 に答える
5

不足しているマクロ機能を置き換えるVisualStudio用のアドインVSScriptがあります。Visual BasicではなくLuaスクリプト言語を使用していますが、試してみることをお勧めします。

レコーダー、IntelliSenseを備えたマクロコードエディターウィンドウ、および単純なデバッガーがあります。アドインは以前のバージョンのVisualStudioもサポートしているため、Visual BasicではなくLua言語を使用する場合は、元のVisualStudioマクロの代わりに使用できます。

于 2012-12-08T20:30:24.967 に答える
3

マクロもなくなるのを見るのはとても悲しかったです。Visual Studio 2012 内で正規表現の検索と置換を使用して、置換に近づくことができます。あなたの場合:

探す:

(.*) (.*);

と置換する:

private $1 _$2;\npublic $1 $2\n{\n  get {return _$2;}\n  set\n  {\n    if(_$2 = value;\n    RaisePropertyChanged("$2");\n  }\n}\n

これにより、マクロの方が適しているプロパティ名の大文字化以外のすべてが得られます。

ただし、正規表現アプローチの利点の 1 つは、入力が単純​​でない場合 (データベース テーブルの DDL ステートメントなど) です。

MSDN からの便利なリンクをいくつか紹介します。

正規表現での置換

Visual Studio での正規表現の使用

于 2012-12-27T17:58:55.050 に答える
2

次のような正規表現で Notepad++ を使用します。

探す:

public (.\*) (.)(.*) \\{ get; set; \\}

交換:

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\); \\}\\}
于 2012-12-21T02:54:31.903 に答える
1

http://devexpress.com/coderushをチェックしてください

テンプレート機能は、ほとんどあなたが望むことをします。

無料の「エクスプレス」バージョンもあります。

于 2012-08-22T11:31:02.910 に答える
1

Visual Studio 2012 のマクロの欠如は私を失望させました.1 回のキープレスで標準的な小さなテキストを挿入するために文字通り常に使用するマクロがいくつかあるからです。そこで、非常に単純なスクリプト拡張パッケージVSScriptsを作成しました。これにより、コマンド ライン プログラムから現在の選択を操作できます。

これは、古いマクロ システムの包括的な完全な代替品であると主張するものではなく、キーボード マクロを提供するものではありませんが、多くの種類のテキスト操作マクロを再作成することを可能にします。

于 2013-04-08T23:52:13.580 に答える
0

個人的にはこれが気に入っています。Visual Commander拡張機能を使用すると、Visual Studio で繰り返し行うタスクを自動化できます。

于 2016-03-17T07:44:00.447 に答える