-
Using the File Explorer, find the managed project sample.
The default location is <drive>:\Program Files\Visual Studio 2005 SDK\<version number>\VisualStudioIntegration\Archive\CS_Samples\Project. Because you will modify this sample, you might want to save a copy before you begin.
-
Open the template file, Project\Templates\Projects\Application.myproj, in Notepad or some other editor.
-
Insert the following line at the end of the first PropertyGroup:
<AssemblyName>Application</AssemblyName>
<MyString>Hello</MyString>
</PropertyGroup> This creates the new project property, MyString.
-
Save the file and exit the editor.
New projects of type MyProject have a project file that is generated from this template.
-
Start Visual Studio and then open the solution Project\MyProject.sln.
-
In Solution Explorer, double-click PropertyPages.cs to open it.
-
Add a field to the fields at the beginning of the GeneralPropertyPage class to hold the new MyString project property:
private string targetPlatformLocation;
private string myString;
-
Add code to the end of the BindProperties method to read the new property from the project file:
this.targetPlatformLocation = this.ProjectMgr.GetProjectProperty(
"TargetPlatformLocation", false);
this.myString = this.ProjectMgr.GetProjectProperty(
"MyString", false);
-
Add code to the ApplyChanges method to write the new property to the project file:
this.ProjectMgr.SetProjectProperty(
"TargetPlatformLocation", this.targetPlatformLocation);
this.ProjectMgr.SetProjectProperty("MyString", this.myString); -
Add a MyString property to the end of the GeneralPropertyPage class to expose the new project property. Give it the category "MyCategory", the display name "My New Property", and the description "This is my new string property.":
public string TargetPlatformLocation
{
get { return this.targetPlatformLocation; }
set { this.targetPlatformLocation = value; IsDirty = true; }
}
[Category("MyCategory")]
[DisplayName("My New Property")]
[Description("This is my new string property.")]
public string MyString
{
get { return myString; }
set { myString = value; IsDirty = true; }
} -
Build and start the project in debug mode by pressing the keyboard shortcut, F5. This starts Visual Studio Exp.
Note |
|---|
| Both versions of Visual Studio are open at this point. |
-
In Visual Studio Exp, on the File menu, point to New, and then click Project. Create a new MyProject Application named SomeProject.
The SomeProject solution and project are created and appear in Solution Explorer.
-
In Solution Explorer, right-click the SomeProject project and then click Properties.
The SomeProject Property Pages dialog box appears. The My New Property property appears in the MyCategory category and has the initial value "Hello".
-
Change the value of My New Property, close the dialog box, and reopen it.
The new value persists.
-
Exit Visual Studio Exp and save changes to the SomeProject solution.
-
On the File menu, point to Open, and then click File to open the file, SomeProject.myproj, in the SomeProject project folder.
The SomeProject project folder is typically located at <drive>:\Documents and Settings\<YourUserName>\My Documents\Visual Studio 2005\Projects\SomeProject.
-
Verify that the MyString property has the latest value that you set in the SomeProject Property Pages dialog box.