none
Using $(ProjectDir) in Propertygroup

    Question

  • Hello All,

    I am trying to define the external program I want to launch when I press F5 in visual studio 2005. So in the MsBuild code of my project, I defined:

    <OutputType>Library</OutputType>
    <StartAction>Program</StartAction>
    <ProgToStart>Tools.Launcher.exe</ProgToStart>

    To explain that my project is a library, that I want to start an external program when i press F5 and that the name of this program is Tools.Launcher.exe. Then, I want to explain that, for a DEBUG configuration, my program is in ProjectDir\bin\Debug\

    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
        <OutputPath>bin\Debug\</OutputPath>
        <StartProgram>$(ProjectDir)$(OutputPath)$(ProgToStart)</StartProgram>
    </PropertyGroup>

    But the problem is that $(ProjectDir) does not seem to be initialized before build process really starts and it results saying that it cannot find 'bin\Debug\Tools.Launcher.exe' instead of giving me all the path "c:\name_of_solution\name_of_project\bin\Debug\Tools.Launcher.exe"

    I've also tried to use $(InputDir) but it gives the same result. Is it possible to do another way or do I have to set, in each of my project, a special property like <MyProjectDir> giving the name of the directory in which the project is stored, and then use $(SolutionDir)$(MyProjectDir)$(OutputPath)$(ProgToStart) ?

    Thanks a lot,

    RemJ
    Thursday, June 15, 2006 1:12 PM

Answers

  • Are your declarations after the <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> element? Sounds like it is before, this would explain why OutputPath is set but ProjectDir is not. OutputPath is set in the proj file itself, but the ProjectDir property is set in the Microsoft.Common.targets file. Your declarations need to go after that Import statement because it depends on the ProjecDir.

    Sayed Ibrahim Hashimi
    www.sedodream.com
    Sunday, June 18, 2006 4:10 AM
    Moderator
  • Oh ok, this explain why it is set in my target AfterBuild and not before!

    Thanks a lot for the answers, my problem is fixed now and i understand well what was the problem!

    Sunday, June 18, 2006 1:03 PM

All replies

  • this might sound like a stupid remark but anyways..

    Why don't you do it like you're "supposed to"? That is, why don't you rightclick your project (possibly set it as startup project), choose properties from the context menu, click the Debug tab, and there provide the application to start, working directory and possible parameters? (those seem to be per-user settings btw and are stored in the .csproj.user file)
    Thursday, June 15, 2006 6:24 PM
  • Because this is a per-user settings and we are many developers working with Perforce so everyone has to set this option on his own workspace and for everyproject and workspaces. Putting it in the .csproj file with MsBuild convention can help to put a relative path and put it in Perforce Depot without any changes required by each developer.

    So does anyone have an idea?
    Friday, June 16, 2006 10:52 AM
  • Are your declarations after the <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> element? Sounds like it is before, this would explain why OutputPath is set but ProjectDir is not. OutputPath is set in the proj file itself, but the ProjectDir property is set in the Microsoft.Common.targets file. Your declarations need to go after that Import statement because it depends on the ProjecDir.

    Sayed Ibrahim Hashimi
    www.sedodream.com
    Sunday, June 18, 2006 4:10 AM
    Moderator
  • Oh ok, this explain why it is set in my target AfterBuild and not before!

    Thanks a lot for the answers, my problem is fixed now and i understand well what was the problem!

    Sunday, June 18, 2006 1:03 PM