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.
In many circumstances, you can use the default build options for your project and have a successful build. There are times, however, when you need to adapt the build script to your needs. I'm going to work with this project called CustomBuildProcess. It has a simple WPF application, and I'm going to choose several different compile options for this application. I am going to start by editing a few of my Tools > Options settings. Let's open this up. We are going to look in Projects and Solutions and pick the General section. Whenever you do a build inside Visual Studio, it can output the results of the build process to this output window.
So, I make sure that this is checked: Show Output window when build starts. I can also control how much information is dumped into that window by clicking on Build and Run and choosing MSBuild output verbosity. By default, I believe at Minimal. You can pick Diagnostic, which gives you a huge amount of information, or you can pick Quiet, which gives you virtually none. So I'll choose this one and then click OK. Now, let me do a build, Ctrl+ Shift+B, and there is my output. Let's try it again.
Choose Tools > Options. This time I'll choose Diagnostic, and do a Ctrl+Shift+B, and now you see, I have got several thousand lines of code, including information about the computer I'm running on and the environment and many, many details. Let me set that back to the original settings. Minimal. Now I have some control over the build process by going to Properties and then clicking this Build section. I am going to autohide his toolbox for a few minutes too.
Here I can control what happens when I do a debug build. I can control all the settings and even the Output folder down here. Also, this is where I can generate my XML documentation for that folder. If I switch to the Release build, now I am controlling what happens when I choose the release build from this dropdown. And in this case, I'm saying to save the files to a different location. We can also customize the Build Events, but before I get to this screen, let me show you a few other options. MSBuild.exe is the tool responsible for building your application, and it relies on a XML script for its instructions.
Now here's a little secret: the build script instructions are stored in an XML file, and they're hiding in plain sight in your project folder. Let me show you where they are. If I were to look at the project folder for this application by right-clicking on this and choosing Open Folder in Windows Explorer, there is a file here called csproj. This is the instruction to Visual Studio of what to load when you open this project within Visual Studio. But also inside this are the build instructions for MSBuild. So if I right-click on this and choose Edit with some editor, like Notepad++, which is the free tool we have on our computer, you'll see that this is nothing more than an XML file.
Now I can open this file inside Visual Studio if I know the secret. Return back to Visual Studio. I right-click on this CustomBuild project and choose Unload. Now all the files that were part of that project are no longer usable inside Visual Studio. Next, I right-click and I choose EditCustomBuildProcess. There is that file, but now we are looking at it as the text file as opposed to the loading it in the Solution Explorer. If you look through this, you'll see that it's just settings for the build engine, where to output the Release build, and it's right here.
That's the Output Path. That's the same thing I was setting just a few minutes ago in the Options dialog. Here is all the references to add for the DLLs, and then down here are the individual files that need to be compiled. It needs to compile a file called App.xaml.cs. There are also other areas. There is PreBuildEvent and PostBuildEvent. And if you want, you can even create your own custom build tasks and add them to this list. I am going to show you how to do a PreBuildEvent and a PostBuildEvent. To do that, I'm going to close this window, then right-click on CustomBuildProject and choose to reload it back into Visual Studio.
Next, I am going to double-click on the Properties section, and I am going to go to this Build Events tab. So let's show you what happens when you do a compile. Any instructions that are inside this section are run first. Virtually anything that you can run at a DOS command prompt you can run inside this box. Then it'll go through the build instructions that are part of the csproj file I just showed you, and then when that's done, it will go out and run any other command you tell it in the Post-build command line. Now, I am going to start here by creating a brand-new folder. I am going to do a make directory .exe.
I am going to call this directory buildDemo. I would like to make sure that this is a fresh directory, so I am going up one line above that and say I would like to remove the directory buildDemo. So I'll remove the directory, then recreate the directory. Let's see if this is working. I'll do a save, and then I'll do a build, and then we'll go and look in our hard drive, look in the bin folder. I was in a debug build, so I'll choose the Debug folder, and there is my buildDemo folder.
Next, I am going to copy a file into that folder. So let me show you how we do that. I go to the PostBuildEvent and what I want to do is take this App.config.test file, I want to make a copy of it, rename it and put it in that new folder I just created. I can find that information about my application and put them in this Post-build event by clicking on this Edit Post- Build button and then clicking on Macros, and this shows me things like output directory. That's how I put the output directory into my script, by putting a dollar sign and then this special keyword here.
So let me show you the text I'm going to run. I'll go to Assets. I'll open this AfterBuild text file. I'll copy this and then paste that right in here. So this says, "Go out to the DOS command." We call the command prompt now, right? "We are going to find the project directory and get this file, App.config.test, and then we are going to make a copy of it, and we are going to put it in the target directory--the output directory--and then in the new folder I just created, buildDemo, and then use this token to rename the file." Let's see if it works.
Right-click here and choose Open Folder in Explorer, open the bin folder, open the Debug folder, drill down into there, and there, I was successful. I have a CustomBuildProcess.config file. There's more I could do with these events. I could build a batch file, for example. The build engine is customizable too. You can create your own build tasks in .NET code and then add them to the build script. Be sure and check out more details in MSDN help.
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.