How do I set the working directory for a Winforms project using dollar sign macros?
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 |
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.
– CRAGIN
Nov 21 '18 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 '18 at 22:30
add a comment |
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 '18 at 22:58
jonsca
8,684115058
8,684115058
asked Nov 21 '18 at 21:53
dabljuesdabljues
1827
1827
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.
– CRAGIN
Nov 21 '18 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 '18 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.
– CRAGIN
Nov 21 '18 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 '18 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.– CRAGIN
Nov 21 '18 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.– CRAGIN
Nov 21 '18 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 '18 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 '18 at 22:30
add a comment |
2 Answers
2
active
oldest
votes
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 |
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 '18 at 22:42
add a comment |
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',
autoActivateHeartbeat: false,
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
});
}
});
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
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
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 |
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 |
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 '18 at 23:02
answered Nov 21 '18 at 22:35
jonscajonsca
8,684115058
8,684115058
add a comment |
add a comment |
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 '18 at 22:42
add a comment |
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 '18 at 22:42
add a comment |
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 '18 at 22:40
answered Nov 21 '18 at 22:35
CRAGINCRAGIN
9,65323271
9,65323271
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 '18 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 '18 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 '18 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 '18 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.
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.– CRAGIN
Nov 21 '18 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 '18 at 22:30