I work on a custom project system that is based on MPF. For the build I have defined a custom target file which defines the minimum set of required targets like Build, Clean and Rebuild so that the project integrates nicely with the Visual Studio IDE; for instance I can trigger a build for a loaded project using F6 shortcut key, whereby the shortcut Ctrl+F5 should also run the application if the build was successful. But, nope... the build output signals success, but Visual Studio does not try to start the application? I´d like to know what´s missing...
My custom project file does not import Microsoft.Common.targets, since it´s not a managed lanugage and most stuff provided by the common build target just do not apply to my project system (also I would like to keep the MSBuild integration as slim as possible).
I read the documentation at: https://msdn.microsoft.com/en-us/library/vstudio/ms171468(v=vs.110).aspx; in the Debugging-section the following MSBuild properties are mentioned: OutputPath, AssemblyName and OutputType; my custom Build target sets all these properties, so I assumed that Visual Studio knows everything which is required to run my application (of course, even if my language service does not support debugging yet).
The Build target definition looks like this...
<Target Name="Build"
DependsOnTargets="PrepareBuildProperties"
Returns="$(TargetPath)">
</Target>
I had a look at the Microsoft.Common.targets file and found a Run target as well. The comment says...
Run the final build output if it is a .EXE
and it´s basically doing this (this is a shortened version of the original target definition)...
<Target Name="Run"
DependsOnTargets="$(RunDependsOn)">
<Exec Command="$(TargetPath) $(StartArguments)"
WorkingDirectory="$(OutDir)" />
</Target>
Should Visual Studio call this target, if I choose the Start without debugging command from the Debug menu, or press Ctrl+F5?
First of all, this statement:
does not make much sense since any language can use MSBuild .Targets files, not just managed languages. For example, building VC++ projects heavily depends on such files. Now back to the problem.
Modern versions of Visual Studio has nothing to do with building projects or running output files. MSBuild manages the whole process. You'll have to specify somewhere that you need some file to be executed after the project gets built.
You can use the AfterBuild target to specify a task to be performed after the build is done. This tag goes inside the Project tag of the project file. You can also specify conditions so that the task is only executed when they are satisfied.
Another way is to use custom build steps as discussed in here. This method is little more flexible.
There is a third way, but probably the least preferred. You can use post build events. To define a post build event, add this under the Project tag:
The problem with this is that it will appear in the Build Events tab of the project properties and so the user can see it and potentially change it. Post build events are designed to be used by the user not the IDE.
The
Exectag you mentioned represents a built-in task indicating that the contents of the tag should be interpreted as a command line that should be executed. The three techniques discussed above are all abstractions on top of theExectask. This task runs when you clickStart without debugging.