How can I get the standard Post- and Pre-build Event functionality?

Hi there,

I use VS.2005. I'm working on the custom MPF package.

I want to use the stardard VS funtionality - Post- and Pre-builds. So, my questions are:

1. Is it possible to get it in principal?

2. If answer for the first question is No - how can I implement somethink like that? I mean how (or where) can I get the information about macros from the standard list?

Can anybody help me? Any help will be much appreciated!

Thanks.

[472 byte] By [DmitryPavlov] at [2007-12-24]
# 1

I guess you are talking about pre- and post build events which are right out of the box when you import the microsoft.common.targets. E.g. you can add the following propertygroup to an iron python project file (pyproj file) from the VS SDK

<PropertyGroup>

<PreBuildEvent>dir</PreBuildEvent>

</PropertyGroup>

Ole

OlePreisler-MSFT at 2007-8-31 > top of Msdn Tech,Visual Studio,Visual Studio Extensibility...
# 2

Hi Ole,

Thank you response! But I didn’t understand how your advice will help in the situation I described. It seams the description was not clear. Well, I’ll try again:

Actually I want to reuse common VS functionality – Post and Pre-build events.

I mean that I also want either to get common UI for build events or the functionality itself.

Is it possible to get this easily? - Somehow like a General tab in Project Properties in IronPython sample?

Does any body know something about this?

Thanks!

DmitryPavlov at 2007-8-31 > top of Msdn Tech,Visual Studio,Visual Studio Extensibility...
# 3

Hi Dimitry,

Unfortunately the Project Property pages are not common VS functionality. If your project is a flavored project of the language projects (vb/c#) you can reuse the Post- and Pre build event property page but that is probably not your situation I guess.

Ole

OlePreisler-MSFT at 2007-8-31 > top of Msdn Tech,Visual Studio,Visual Studio Extensibility...
# 4

Hi Ole,

Thank you for your response!

Right you are - that is not my case. My project is for custom language. So , what about my second question - how can I retrive th marcos list containing such marcos as TARGETDIR and so on?

DmitryPavlov at 2007-8-31 > top of Msdn Tech,Visual Studio,Visual Studio Extensibility...
# 5

Hi there,

Up.

I am still interesting how to get standard marcos (e.g. $(ProjectDir), $(ConfigurationName), etc. ) for my custom implementation of Build Events in Project Properties to make it most possibly close to C# project implementation?

Any ideas will be much apprecaited!

Thanks.

DmitryPavlov at 2007-8-31 > top of Msdn Tech,Visual Studio,Visual Studio Extensibility...
# 6
Maybe I need to declare some variables in my targets file? Does it make sense?
DmitryPavlov at 2007-8-31 > top of Msdn Tech,Visual Studio,Visual Studio Extensibility...
# 7

That is the correct way to go!

Ole

OlePreisler-MSFT at 2007-8-31 > top of Msdn Tech,Visual Studio,Visual Studio Extensibility...
# 8

Thank you, Ole!

I've researched that standard macros used in C# projects declared in according targets file.

For example this fragment of %WINDOWS%\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets file declares several macros:

<!--

IDE Macros available from both integrated builds and from command line builds.

The following properties are 'macros' that are available via IDE for

pre and post build steps.

-->

<PropertyGroup>

<TargetExt Condition="'$(OutputType)'=='exe'">.exe</TargetExt>

<TargetExt Condition="'$(OutputType)'=='winexe'">.exe</TargetExt>

<TargetExt Condition="'$(OutputType)'=='library'">.dll</TargetExt>

<TargetExt Condition="'$(OutputType)'=='module'">.netmodule</TargetExt>

</PropertyGroup>

<PropertyGroup>

<OutDir Condition=" '$(OutDir)' == '' ">$(OutputPath)</OutDir>

<!-- Example, bin\Debug\ -->

<!-- Ensure OutDir has a trailing slash, so it can be concatenated -->

<OutDir Condition="'$(OutDir)' != '' and !HasTrailingSlash('$(OutDir)')">$(OutDir)\</OutDir>

<ProjectName Condition=" '$(ProjectName)' == '' ">$(MSBuildProjectName)</ProjectName>

<!-- Example, MyProject -->

<TargetName Condition=" '$(TargetName)' == '' ">$(AssemblyName)</TargetName>

<!-- Example, MyAssembly -->

<ProjectFileName Condition=" '$(ProjectFileName)' == '' ">$(MSBuildProjectFile)</ProjectFileName>

<!-- Example, MyProject.csproj -->

<ProjectExt Condition=" '$(ProjectExt)' == '' ">$(MSBuildProjectExtension)</ProjectExt>

<!-- Example, .csproj -->

<TargetFileName Condition=" '$(TargetFileName)' == '' ">$(TargetName)$(TargetExt)</TargetFileName>

<!-- Example, MyAssembly.dll -->

</PropertyGroup>

I've implemented this way. That works ok. All declared in my custom targets file variables are recognized in build events command line and also are accessible programmatically from the code via GetProjectProperty(string propertyName, bool resetCache) method of ProjectNode class.

DmitryPavlov at 2007-8-31 > top of Msdn Tech,Visual Studio,Visual Studio Extensibility...
# 9

I’ve re-read all topics and decided to create one more post to sum up all the information I gathered. So this post is kind of small walkthrough.

Walkthrough: How to implement Pre- and Post- Build Events support in your custom package:


To add pre- and post-build functionality into your custom package you need:

1. Add two targets into your targets file:

<Target Name="PreBuildEvent">

<Exec Command="$(PreBuildEvent)" Condition=" '$(PreBuildEvent)' != '' "/>

</Target>

<Target Name="PostBuildEvent">

<Exec Command="$(PostBuildEvent)" Condition=" '$(PostBuildEvent)' != '' "/>

</Target>

Value of the command attribute is a variable which refers to project property. So for targets specified above you need to have the somethink like that in your project file:

<PropertyGroup>

<PreBuildEvent> [the command line is stored there and it is set from your project properties page ] </PreBuildEvent>

<PostBuildEvent> [the command line is stored there and it is set from your project properties page ] </PostBuildEvent>

</PropertyGroup>

More detailed information about Project Property page implementation you can find in SDK Walkthrough: Exposing Project and Configuration Properties (C#)

2. Call these two targets before and after build target is called. This can be organized in this manner:

<PropertyGroup>

<BuildDependsOn>PreBuildEvent;Compile;PostBuildEvent</BuildDependsOn>

</PropertyGroup>

<Target Name="Build" DependsOnTargets="$(BuildDependsOn)">

<Message Text="Build" />

</Target>

3. You can to create your custom macro like this one:

<!—My Macros -->

<PropertyGroup>

<WindowsDir Condition=" '$(WindowsDir)' == '' ">C:\Windows\</ WindowsDir >

</PropertyGroup>

4. And use it in your pre-build event mentioned in step 2 above

<PreBuildEvent>DIR $(WindowsDir)</PreBuildEvent>

That’s all. Enjoy!

DmitryPavlov at 2007-8-31 > top of Msdn Tech,Visual Studio,Visual Studio Extensibility...

Visual Studio

Site Classified