Pages

Friday, March 25, 2011

We can extend the existing Visual Studio environment by automation techniques provided by Visual Studio and DotNet framework. We can add our own features to the Visual Studio by creating Add-Ins. Add-In is a complied DLL which run in visual studio IDE.

Here in this blog post we are going to create an Visual Studio Add-In which will;

1. Find and change the name of the Namespace defined in c# source code2. Find and change the name of the Class defined in c# source code3. Find and change the name of the Property defined in the c# source code4. Find and change the name of the function defined in the c# source code5. Find the attributes defined in a class and if required we can change the values defined inside the attribute6. Find the attributes of properties defined in a c# source code file.7. And more over we will be able to iterate through the C# source code and find out the Namespace, Class, Functions, Properties, Delegates, Events and Struct, we can do any kind of manipulation with in the code.

53:// To change the name of the property defined in the c# source code file

54: cFucntion.Name = "NewcFucntionName";

55:

56: }

57:

58:if (codeElement.Kind == vsCMElement.vsCMElementNamespace)

59: {

60: CodeNamespace cNamespace = (CodeNamespace)codeElement;

61: MessageBox.Show("Namespace name is " + codeElement.Name);

62:

63:// To change the name of the namespace defined in the c# source code file

64: cNamespace.Name = "NewcNameSpaceName";

65: }

66:

67:if (codeElement.Kind == vsCMElement.vsCMElementStruct)

68: {

69: CodeStruct CodeStruct = (CodeStruct)codeElement;

70: MessageBox.Show("Struct name is " + codeElement.Name);

71:

72:// To change the name of the Struct defined in the c# source code file

73: CodeStruct.Name = "NewcStructName";

74: }

75:

76:if (codeElement.Kind == vsCMElement.vsCMElementEnum)

77: {

78: CodeEnum CodeEnum = (CodeEnum)codeElement;

79: MessageBox.Show("Enum name is " + codeElement.Name);

80:

81:// To change the name of the Enum defined in the c# source code file

82: CodeEnum.Name = "NewcEnumName";

83: }

84:

85:if (codeElement.Kind == vsCMElement.vsCMElementDelegate)

86: {

87: CodeDelegate CodeDelegate = (CodeDelegate)codeElement;

88: MessageBox.Show("Delegate name is " + codeElement.Name);

89:

90:// To change the name of the delegate defined in the c# source code file

91: CodeDelegate.Name = "NewcDelegateName";

92: }

93:

94:if (codeElement.Kind == vsCMElement.vsCMElementEvent)

95: {

96: CodeEvent CodeEvent = (CodeEvent)codeElement;

97: MessageBox.Show("Event name is " + codeElement.Name);

98:

99:// To change the name of the Event defined in the c# source code file

100: CodeEvent.Name = "NewcEventName";

101: }

102:

103:foreach (CodeElement childElement in codeElement.Children)

104: {

105: ExamineCodeElement(childElement);

106: }

107: }

108:catch

109: {

110://

111: }

112: }

You can find the complete source code here. The .Zip file contains two projects one is the Add-In application and the other one is a sample project to test the Add-In functionalities.

To test the project first follow the below steps:

1. Build the “VSAddIn” project.

2. Once you build the solution you will get a Add-In File called “VSAddIn.AddIn” in your project folder. Copy the file and got to My Documents –> Visual Studio 2008 –> Add-Ins and paste it there.

3. Edit that Add-In file in notepad. You can find the xml tag <Assembly>Project1.dll</Assembly>. Change the path to the Project1.dll file in you project debug folder. Now open the sample project application go to Tools menu You can find the Add-In “VSAddIn” .

4. Again go back to the Add-In Application project got to Tools Menu Click on Attach process. A number of processes will be listed over there, select the sample project application. Now the Add-In application is ready to debug.

5. Now got to the sample project application and select the “VSAddIn”.

If you need further assistance on how to extend this article according to your need please let me know via comments.

2
comments:

Thanks for the awesome shareHi we at Colan Infotech Private Limited , a company which is Situated in US and India, will provide you best service and our talented team will assure you best result and we are familiar with international markets, We work with customers in a wide variety of sectors. Our talented team can handle all the aspects of custom application development, we are the best among the dot net development companies in Chennai . asp .net web development company

Post a Comment

Facebook Badge

AddThis

About Me

I am a Senior Developer in Dot net Application development. Now I am working in silverlight and wcf. In my career I got opportunity to work with latest technologies like Windows Mobile, WPF, Silverlight, WCF, Windows Azure, Python for S60 Devices. But from above all technologies I liked Silverlight and WCF very much, so I decided start a blog to share my coding experience.