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:

I get this error:

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
add a comment |
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:

I get this error:

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
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
add a comment |
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:

I get this error:

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
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:

I get this error:

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
visual-studio visual-studio-2017
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
add a comment |
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
add a comment |
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.
add a comment |
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.
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
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
edited Nov 21 at 23:02
answered Nov 21 at 22:35
jonsca
8,588114757
8,588114757
add a comment |
add a comment |
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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