How do I set the working directory for a Winforms project using dollar sign macros?











up vote
2
down vote

favorite












I am working on a C# app, the contents of it I guess do not matter. Basically, I often use Save/OpenFileDialogs in it. And I use an initial dir property, to make it more convenient, and I set it to the current working directory.



When I have a release build, I pack my application and have all the dirs inside, so it works well. But when I actually debug it in Visual Studio I want to set the working directory which is different from bin/Debug. And so I did. I wrote a literal path, like C:SomethingblahxyzworkingDir. And it works. The problem is I have two machines that I am working on, and this path won't work on the other machine.



I know about the macros like $(ProjectDir) in Visual Studio, so I wanted to use them. Unfortunately when I type i.e. $(ProjectDir) in here:



enter image description here



I get this error:



enter image description here



Do you guys know what may be the issue? I thought this is actually a valid macro, according to the MSDN










share|improve this question




















  • 1




    @dabljues Oh. $(ProjectDir) is definitely a valid macro, but it may not be for that specific field. Also, make sure that directory really exists (I know, sounds obvious). I'll make that my answer and will delete it if wrong.
    – Kit
    Nov 21 at 22:26












  • Oh, right, forgot to add. It is a Windows Forms application. The solution contains two projects (but I guess that doesn't matter since I am setting this for only one of them).
    – dabljues
    Nov 21 at 22:30















up vote
2
down vote

favorite












I am working on a C# app, the contents of it I guess do not matter. Basically, I often use Save/OpenFileDialogs in it. And I use an initial dir property, to make it more convenient, and I set it to the current working directory.



When I have a release build, I pack my application and have all the dirs inside, so it works well. But when I actually debug it in Visual Studio I want to set the working directory which is different from bin/Debug. And so I did. I wrote a literal path, like C:SomethingblahxyzworkingDir. And it works. The problem is I have two machines that I am working on, and this path won't work on the other machine.



I know about the macros like $(ProjectDir) in Visual Studio, so I wanted to use them. Unfortunately when I type i.e. $(ProjectDir) in here:



enter image description here



I get this error:



enter image description here



Do you guys know what may be the issue? I thought this is actually a valid macro, according to the MSDN










share|improve this question




















  • 1




    @dabljues Oh. $(ProjectDir) is definitely a valid macro, but it may not be for that specific field. Also, make sure that directory really exists (I know, sounds obvious). I'll make that my answer and will delete it if wrong.
    – Kit
    Nov 21 at 22:26












  • Oh, right, forgot to add. It is a Windows Forms application. The solution contains two projects (but I guess that doesn't matter since I am setting this for only one of them).
    – dabljues
    Nov 21 at 22:30













up vote
2
down vote

favorite









up vote
2
down vote

favorite











I am working on a C# app, the contents of it I guess do not matter. Basically, I often use Save/OpenFileDialogs in it. And I use an initial dir property, to make it more convenient, and I set it to the current working directory.



When I have a release build, I pack my application and have all the dirs inside, so it works well. But when I actually debug it in Visual Studio I want to set the working directory which is different from bin/Debug. And so I did. I wrote a literal path, like C:SomethingblahxyzworkingDir. And it works. The problem is I have two machines that I am working on, and this path won't work on the other machine.



I know about the macros like $(ProjectDir) in Visual Studio, so I wanted to use them. Unfortunately when I type i.e. $(ProjectDir) in here:



enter image description here



I get this error:



enter image description here



Do you guys know what may be the issue? I thought this is actually a valid macro, according to the MSDN










share|improve this question















I am working on a C# app, the contents of it I guess do not matter. Basically, I often use Save/OpenFileDialogs in it. And I use an initial dir property, to make it more convenient, and I set it to the current working directory.



When I have a release build, I pack my application and have all the dirs inside, so it works well. But when I actually debug it in Visual Studio I want to set the working directory which is different from bin/Debug. And so I did. I wrote a literal path, like C:SomethingblahxyzworkingDir. And it works. The problem is I have two machines that I am working on, and this path won't work on the other machine.



I know about the macros like $(ProjectDir) in Visual Studio, so I wanted to use them. Unfortunately when I type i.e. $(ProjectDir) in here:



enter image description here



I get this error:



enter image description here



Do you guys know what may be the issue? I thought this is actually a valid macro, according to the MSDN







visual-studio visual-studio-2017






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 at 22:58









jonsca

8,588114757




8,588114757










asked Nov 21 at 21:53









dabljues

1206




1206








  • 1




    @dabljues Oh. $(ProjectDir) is definitely a valid macro, but it may not be for that specific field. Also, make sure that directory really exists (I know, sounds obvious). I'll make that my answer and will delete it if wrong.
    – Kit
    Nov 21 at 22:26












  • Oh, right, forgot to add. It is a Windows Forms application. The solution contains two projects (but I guess that doesn't matter since I am setting this for only one of them).
    – dabljues
    Nov 21 at 22:30














  • 1




    @dabljues Oh. $(ProjectDir) is definitely a valid macro, but it may not be for that specific field. Also, make sure that directory really exists (I know, sounds obvious). I'll make that my answer and will delete it if wrong.
    – Kit
    Nov 21 at 22:26












  • Oh, right, forgot to add. It is a Windows Forms application. The solution contains two projects (but I guess that doesn't matter since I am setting this for only one of them).
    – dabljues
    Nov 21 at 22:30








1




1




@dabljues Oh. $(ProjectDir) is definitely a valid macro, but it may not be for that specific field. Also, make sure that directory really exists (I know, sounds obvious). I'll make that my answer and will delete it if wrong.
– Kit
Nov 21 at 22:26






@dabljues Oh. $(ProjectDir) is definitely a valid macro, but it may not be for that specific field. Also, make sure that directory really exists (I know, sounds obvious). I'll make that my answer and will delete it if wrong.
– Kit
Nov 21 at 22:26














Oh, right, forgot to add. It is a Windows Forms application. The solution contains two projects (but I guess that doesn't matter since I am setting this for only one of them).
– dabljues
Nov 21 at 22:30




Oh, right, forgot to add. It is a Windows Forms application. The solution contains two projects (but I guess that doesn't matter since I am setting this for only one of them).
– dabljues
Nov 21 at 22:30












2 Answers
2






active

oldest

votes

















up vote
1
down vote



accepted










It doesn't appear that you can apply this macro in that dialog. Leave the value blank and go to the directory for the solution, drill down into the folder for the project and you should see [ProjectName].csproj



Add the following StartWorkingDirectory setting to to the PropertyGroup for the Debug config.



The property group is:



<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">


And add:



<StartWorkingDirectory>$(ProjectDir)</StartWorkingDirectory>


So it ends up looking like:



<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>binDebug</OutputPath>
<StartWorkingDirectory>$(ProjectDir)</StartWorkingDirectory>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>


The value still won't show up in the dialog, but if you use the working directory in your program, the value will be correct.






share|improve this answer






























    up vote
    2
    down vote













    You cannot use that (valid) macro for that field as Visual Studio does not apply macros there. What makes me believe that is that it seems to be interpreting what you entered literally.



    You might be better off by doing something in the code itself to use the project directory. If so, you may want to check to see if the debugger is attached, at least for the purposes of development and "convenience" (e.g. Debugger.IsAttached) and then get the CodeBase property of the executing assembly or the CurrentDirectory. That gives you the convenience you're looking for while debugging. For production, of course, you might want a different strategy.






    share|improve this answer























    • As I said in the comment of @jonsca answer - for this particular case it's an overkill for me. Thank you for the input, maybe VS team will change that some time
      – dabljues
      Nov 21 at 22:42











    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53420986%2fhow-do-i-set-the-working-directory-for-a-winforms-project-using-dollar-sign-macr%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote



    accepted










    It doesn't appear that you can apply this macro in that dialog. Leave the value blank and go to the directory for the solution, drill down into the folder for the project and you should see [ProjectName].csproj



    Add the following StartWorkingDirectory setting to to the PropertyGroup for the Debug config.



    The property group is:



    <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">


    And add:



    <StartWorkingDirectory>$(ProjectDir)</StartWorkingDirectory>


    So it ends up looking like:



    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>binDebug</OutputPath>
    <StartWorkingDirectory>$(ProjectDir)</StartWorkingDirectory>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    </PropertyGroup>


    The value still won't show up in the dialog, but if you use the working directory in your program, the value will be correct.






    share|improve this answer



























      up vote
      1
      down vote



      accepted










      It doesn't appear that you can apply this macro in that dialog. Leave the value blank and go to the directory for the solution, drill down into the folder for the project and you should see [ProjectName].csproj



      Add the following StartWorkingDirectory setting to to the PropertyGroup for the Debug config.



      The property group is:



      <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">


      And add:



      <StartWorkingDirectory>$(ProjectDir)</StartWorkingDirectory>


      So it ends up looking like:



      <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
      <PlatformTarget>AnyCPU</PlatformTarget>
      <DebugSymbols>true</DebugSymbols>
      <DebugType>full</DebugType>
      <Optimize>false</Optimize>
      <OutputPath>binDebug</OutputPath>
      <StartWorkingDirectory>$(ProjectDir)</StartWorkingDirectory>
      <DefineConstants>DEBUG;TRACE</DefineConstants>
      <ErrorReport>prompt</ErrorReport>
      <WarningLevel>4</WarningLevel>
      </PropertyGroup>


      The value still won't show up in the dialog, but if you use the working directory in your program, the value will be correct.






      share|improve this answer

























        up vote
        1
        down vote



        accepted







        up vote
        1
        down vote



        accepted






        It doesn't appear that you can apply this macro in that dialog. Leave the value blank and go to the directory for the solution, drill down into the folder for the project and you should see [ProjectName].csproj



        Add the following StartWorkingDirectory setting to to the PropertyGroup for the Debug config.



        The property group is:



        <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">


        And add:



        <StartWorkingDirectory>$(ProjectDir)</StartWorkingDirectory>


        So it ends up looking like:



        <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
        <PlatformTarget>AnyCPU</PlatformTarget>
        <DebugSymbols>true</DebugSymbols>
        <DebugType>full</DebugType>
        <Optimize>false</Optimize>
        <OutputPath>binDebug</OutputPath>
        <StartWorkingDirectory>$(ProjectDir)</StartWorkingDirectory>
        <DefineConstants>DEBUG;TRACE</DefineConstants>
        <ErrorReport>prompt</ErrorReport>
        <WarningLevel>4</WarningLevel>
        </PropertyGroup>


        The value still won't show up in the dialog, but if you use the working directory in your program, the value will be correct.






        share|improve this answer














        It doesn't appear that you can apply this macro in that dialog. Leave the value blank and go to the directory for the solution, drill down into the folder for the project and you should see [ProjectName].csproj



        Add the following StartWorkingDirectory setting to to the PropertyGroup for the Debug config.



        The property group is:



        <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">


        And add:



        <StartWorkingDirectory>$(ProjectDir)</StartWorkingDirectory>


        So it ends up looking like:



        <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
        <PlatformTarget>AnyCPU</PlatformTarget>
        <DebugSymbols>true</DebugSymbols>
        <DebugType>full</DebugType>
        <Optimize>false</Optimize>
        <OutputPath>binDebug</OutputPath>
        <StartWorkingDirectory>$(ProjectDir)</StartWorkingDirectory>
        <DefineConstants>DEBUG;TRACE</DefineConstants>
        <ErrorReport>prompt</ErrorReport>
        <WarningLevel>4</WarningLevel>
        </PropertyGroup>


        The value still won't show up in the dialog, but if you use the working directory in your program, the value will be correct.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 21 at 23:02

























        answered Nov 21 at 22:35









        jonsca

        8,588114757




        8,588114757
























            up vote
            2
            down vote













            You cannot use that (valid) macro for that field as Visual Studio does not apply macros there. What makes me believe that is that it seems to be interpreting what you entered literally.



            You might be better off by doing something in the code itself to use the project directory. If so, you may want to check to see if the debugger is attached, at least for the purposes of development and "convenience" (e.g. Debugger.IsAttached) and then get the CodeBase property of the executing assembly or the CurrentDirectory. That gives you the convenience you're looking for while debugging. For production, of course, you might want a different strategy.






            share|improve this answer























            • As I said in the comment of @jonsca answer - for this particular case it's an overkill for me. Thank you for the input, maybe VS team will change that some time
              – dabljues
              Nov 21 at 22:42















            up vote
            2
            down vote













            You cannot use that (valid) macro for that field as Visual Studio does not apply macros there. What makes me believe that is that it seems to be interpreting what you entered literally.



            You might be better off by doing something in the code itself to use the project directory. If so, you may want to check to see if the debugger is attached, at least for the purposes of development and "convenience" (e.g. Debugger.IsAttached) and then get the CodeBase property of the executing assembly or the CurrentDirectory. That gives you the convenience you're looking for while debugging. For production, of course, you might want a different strategy.






            share|improve this answer























            • As I said in the comment of @jonsca answer - for this particular case it's an overkill for me. Thank you for the input, maybe VS team will change that some time
              – dabljues
              Nov 21 at 22:42













            up vote
            2
            down vote










            up vote
            2
            down vote









            You cannot use that (valid) macro for that field as Visual Studio does not apply macros there. What makes me believe that is that it seems to be interpreting what you entered literally.



            You might be better off by doing something in the code itself to use the project directory. If so, you may want to check to see if the debugger is attached, at least for the purposes of development and "convenience" (e.g. Debugger.IsAttached) and then get the CodeBase property of the executing assembly or the CurrentDirectory. That gives you the convenience you're looking for while debugging. For production, of course, you might want a different strategy.






            share|improve this answer














            You cannot use that (valid) macro for that field as Visual Studio does not apply macros there. What makes me believe that is that it seems to be interpreting what you entered literally.



            You might be better off by doing something in the code itself to use the project directory. If so, you may want to check to see if the debugger is attached, at least for the purposes of development and "convenience" (e.g. Debugger.IsAttached) and then get the CodeBase property of the executing assembly or the CurrentDirectory. That gives you the convenience you're looking for while debugging. For production, of course, you might want a different strategy.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 21 at 22:40

























            answered Nov 21 at 22:35









            Kit

            8,61123168




            8,61123168












            • As I said in the comment of @jonsca answer - for this particular case it's an overkill for me. Thank you for the input, maybe VS team will change that some time
              – dabljues
              Nov 21 at 22:42


















            • As I said in the comment of @jonsca answer - for this particular case it's an overkill for me. Thank you for the input, maybe VS team will change that some time
              – dabljues
              Nov 21 at 22:42
















            As I said in the comment of @jonsca answer - for this particular case it's an overkill for me. Thank you for the input, maybe VS team will change that some time
            – dabljues
            Nov 21 at 22:42




            As I said in the comment of @jonsca answer - for this particular case it's an overkill for me. Thank you for the input, maybe VS team will change that some time
            – dabljues
            Nov 21 at 22:42


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53420986%2fhow-do-i-set-the-working-directory-for-a-winforms-project-using-dollar-sign-macr%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Sphinx de Gizeh

            Dijon

            Guerrita