Question

I have two questions re: visual studio 2008 and post-build events.

1) How do i dynamically list the msbuild.exe full path, to be called by the post-build event? Currently, i have the following (which works beautifully, btw):-

C:\Windows\Microsoft.NET\Framework64\v3.5\msbuild.exe 
    "$(ProjectDir)MSBuild\MSBuildSettings.xml"

.. but that would only work if u have a x64 bit environment. Is there a way to use some built in magic setting? eg. $(MsBuildPath)msbuild.exe "blah....xml" ??

2) My msbuild task does some stuff then generates a txt file as the output. I define the output path in the msbuild xml file as such..

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/MsBuild/2003">
    <UsingTask TaskName="CustomTask" AssemblyFile="MyAssembly.dll"/>
    <Target>
        <CustomTask
           ...
           OutputFile="Foo.txt"
        />
    <Target>
</Project>

How can i pass in the real output folder, to the msbuild file? I tried...

OutputFile="$(OutDir)Foo.txt"

but that failed :(

Cheers!

Update #1 - Answer to the second question..

I've figured out a way to answer the second question -- not sure if it's the best one though .. so I'm open to other ideas :)

XML file changes :: add a property group that sets the internal variable name IF no outside arguments were passed to the msbuild.exe executable.

    <PropertyGroup>
        <OutputFile Condition=" '$(OutputFile)'=='' ">
            ..\SomeFolder\Foo.txt</OutputFile>
    </PropertyGroup>

    <Target>
        <CustomTask
           ...
           OutputFile="$(OutputFile)"
        />
    <Target>
</Project>

Now, call the msbuild executable like ...

msbuild.exe "C:\Temp Foo\Blah\MsbuildSettings" /p:OutputFile="C:\Folder 1\Folder 2\blah\"

and that works :)

Was it helpful?

Solution

For question 1, use property MSBuildBinPath

For question 2, use property OutputPath (C# or VB projects)

OutputFile="$(OutputPath)Foo.txt"

OTHER TIPS

You could put your custom task inside the vbproj (csproj if it's a c# project) file and then have the post-build event use the VS-defined MSBuild variables. I'm thinking of this process off the top of my head, so bear with me on this, lol.

  1. In Visual Studio, unload the project you want to have the post-build event with, and then right-click on the unloaded project node and select 'Edit...'.
  2. Put the UsingTask at the top, just like what you have.
  3. Reload the project, and open up the project properties and go to edit the post-build event there.
  4. You should be able to access all those nifty variables now, and add them to your custom task.

Project files are MSBuild scripts in themselves, allowing you to do all sorts of nifty MSBuild scripting tricks.

Edit: Sorry, I don't have an answer for the first question you asked.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top