Start learning with our library of video tutorials taught by experts. Get started
Viewers: in countries Watching now:
In Visual Studio 2010 Essential Training, author Walt Ritscher demonstrates how to use Visual Studio 2010 Professional to develop full-featured applications targeting a variety of platforms. Starting with an overview of the integrated developer environment, the course covers working with code editors, navigating and formatting code, and deploying applications. Also included are tutorials on running performance and load tests, and debugging code. Exercise files accompany the course.
Creating an external help file is a common type of documentation. Note: For this movie, I am not talking about help for the end user of the application, but rather about code documentation. This documentation is intended for other programmers to use, to get a better understanding of a code API. In order to build the Help files later in this movie, you need to install some additional open source tools. These tools are available in your Exercise File folder, in the Installers folder.
There are three tools that you need to install: GhostDoc, Sandcastle, and SandcastleBuildersSetup. Sandcastle itself is the help-generation tool from Microsoft. It only works at the command line. SandcastleBuilder is a graphics interface that works with Sandcastle, and I am going to show that later in this movie. GhostDoc is a plug-in for Visual Studio that helps you write the XML comments you need. So install those and then continue with the movie. Now I am in Visual Studio. I am inside a project called BookLib, which is inside the Documenting Solution.
Both C# and Visual Basic support special help comments called XML comments. When Visual Studio encounters these XML comments, it can generate a separate XML file as part of the compile process. Then this XML file is used by the Help tools as a basis for creating the help files. My plan is to document this class here, called the Book class. So I will double-click on it. It's a simple class that has three public properties, and I see I need to make this class public for later. And then it has two methods called UpdatePrice, two overloads of the same method.
So my idea is that I want to document this method and make it easier for a developer who is using this function to know how it's going to work. What I do is I go to the line immediately above this method, and I type in three comment slashes. And you see the Visual Studio stubs in these special XML tags that are inside these three slashes. This is a summary about what this function does. So I will say, "Update the price of a book based on ID." Then I can come down here and say something about these different parameters "as a number", right? Whereas these other overload down here will have a percentage value passed into it.
Now, I am going to compile the application. It asks me if I want to save the changes. I am going to say yes. You may not see that dialog on your computer. Let's look at this from the perspective of a developer who is using this class. Over here in this code, I have instantiated an instance of the book, and I am calling UpdatePrice. Now I am going to move my cursor right here, and I am going to do a Ctrl+Shift+Spacebar, which launches the IntelliSense. You can see that it says here "Update the price of a book, based on ID." And then I am going to go over to this one, and you will see in the bottom it says, "new price as a number".
So those comments that I just wrote are now showing up in the IntelliSense for the developer that's calling my method. So you can go through your application, sprinkling useful comments in there, and you will get a much better application in the long run, for the other programmers that are using it. Now I can formalize this and put this in a Help file too, and then the user could press-- user in this case being another developer--could click on this and press F1 to launch the Help file and read more help about it. So what I need to do now is continue to add XML comments. For instance, I can come up and add them at the class level up here.
Now this can get tedious, so there is a special tool that you can add to Visual Studio, called GhostDoc. Let me show you how GhostDoc works. It's in my Tools menu, right up here at the top. That's because I installed it earlier today. I'll click on this public int ID, and then I'll go to Tools > GhostDoc and choose Document this. So this is very similar to me writing the slash, slash, slash, but the difference that GhostDoc give me is that it attempts to write something useful in here.
So it's used the value of The ID, and it's used the words "gets or sets the ID". That's the main difference in using this one. So I will do this few more times. All right, and then I will come up to the class, public class Book, like that, and now I am ready to generate my Help file. So to generate the Help file, I need to go into my project, Properties section.
Double-click on this property item over here in the Solution Explorer. I need to go to Build -- let me close this window down here in the bottom, so you can see more--and then down here in the bottom section of the Build tab, I need to check the XML documentation check box. Now when I do my compile, it's going to generate an additional XML file. Let me show you that file. I will right-click on my Project, choose Open folder in Windows Explorer. I'll go to my compile folder, which is bin > Debug, and there is my executable, and there is my XML file.
Now I am ready to make the actual Help file. To do that, I need to run that Sandcastle tool. So I am going to go out to my Start menu and type in "Sandcastle". I am using this one here, the Sandcastle Help File Builder GUI. Maximize the window. Then I will go to File > New Project. I'll put this on my Desktop, in my Exercise Files folder, Chapter 05.
You can see I have already generated some earlier today. I'll Click on Save. I am going to call this one FirstTrial. Oops! I went one folder too deep. Let me go back one folder. There we go. FirstTrial. I am nearly done. There are a couple of changes you need to make. One is you need to change your output folder. If you're storing your files in the Desktop, you cannot compile the Help file. So I need to click on this sort alphabetical, and then scroll down here to the WorkingPath. And I need to pick a folder name somewhere that won't get erased.
My C drive. And then can over here I can say BuildHere. Now what's going to happen is when I compile my Help, it's going to generate this folder, make all the files, and then when it's done it's going to erase this folder. So don't point this to any folder that you care about your files, okay? I am ready to do my Build. Now I just need to tell it where to find that XML file. So I come over here to the Documentation Sources, right-click, and choose Add Documentation Source, and then I need to go over to that bin folder I showed you a few minutes ago. Documenting > BookLib > bin, now I am going to the Debug folder.
Let's choose this XML file and click Open. At this point, I think I am ready to make the Help file. So I go to Documentation and choose Build Project. My build is done. The Help folder was generating when I did the Build. You'll see that there is a Documentation.chm file. I can run that from this folder, or I can run it from the Sandcastle build tool. I'll run it from here. And as you can see, it's a basic Help file. It shows I have a class called Book. There is my description I wrote: "An example of a Book".
I can click on this and see the syntax for the Book, and you see that it drives from System.Object. I can go over here and look at the Book methods. There are two overloads of the UpdatePrice Method. And again, my comments are showing up here. If you look at the parameters, you'll see the newPrices. The new price has a number, so that carried over. I am getting some warnings, because I haven't provided all of the information in the XML comment file, so the compiler caught this and said, "You never provided any information about that other parameter," and there are the Properties.
Creating Help is a critical part of a product lifecycle. These Help tools are good for creating help for other programmers. If you are fortunate enough to be building developer tools, then GhostDoc and Sandcastle are just the tools you need. If you are building consumer-based applications, these tools are of little value. For consumer help files, you need to investigate third-party tools.
Find answers to the most frequently asked questions about Visual Studio 2010 Essential Training.
Here are the FAQs that matched your search "":
Sorry, there are no matches for your search ""—to search again, type in another word or phrase and click search.
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.