Click here to Skip to main content
15,891,769 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to get the Application Bin/Debug-Path during DesignTime

With Google I found several entries (for example an StackOverFlow) but none of them are working ...

What I have tried:

Application.CommonAppDataPath
Application.ExecutablePath
Application.StartupPath
Application.LocalUserAppDataPath
Assembly.GetEntryAssembly.CodeBase
Directory.GetCurrentDirectory
AppDomain.CurrentDomain.BaseDirectory
My.Application.Info.DirectoryPath

None of them above deliver the right path ... :(
Posted
Updated 6-Jul-17 0:44am
v3
Comments
Richard MacCutchan 5-Jul-17 6:43am    
It depends on where you want to reference the path. Perhaps you could explain exactly what you are trying to do.
Ralf Meier 5-Jul-17 6:48am    
I want to save some data, generated by a Component during DesignTime, into this path.
I know that the Designer itself could store the data of a Component into the Designer-Script of the Form where it is placed on but I want to have it Independent.

But your question is not quiet clear for me - what Information do you need ?
Richard MacCutchan 5-Jul-17 7:32am    
Sorry, but I am still not clear. The project properties contains the relative path to bin\Debug, but I am not sure how you address that in the designer. In C++ it is fairly simple as all these values are macros that can be accessed by shell commands. C# and VB.NET do not appear to have the same facility, unless you can somehow access the properties via the Visual Studio COM interface using a script.
Ralf Meier 5-Jul-17 8:24am    
I think you understood what I mean (or want to know).
My Application is stored under :
C:\Users\myName\Documents\Visual Studio 2013\Projects\myProject\MyProject
So the path I want to get is :
C:\Users\myName\Documents\Visual Studio 2013\Projects\myProject\MyProject\bin\Debug

But none of the articles I found and the namespaces I tried deliver this path - I also will be glad if I get the Application-path. The sub-path "bin\debug" could be added by constant ...
Richard MacCutchan 5-Jul-17 8:49am    
Can you just use the path "bin\Debug", since that should be relative to your project directory?

1 solution

Not the whole Solution but a part of it.
This code-snippet gives the Project-path :
VB
Dim dte As EnvDTE.DTE = System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE")
Dim dir As String = Path.GetDirectoryName(dte.Solution.FullName)

To get it work it is necessary to add a reference to "Microsoft.Development Environment"

see also : Referencing the DTE Object[^]
 
Share this answer
 
Comments
Richard MacCutchan 6-Jul-17 7:13am    
Well done finding it. In C++ they call it the Project Model.
Ralf Meier 6-Jul-17 8:17am    
Thanks Richard (also für your vote) ... it was a hard way to go ...
Richard MacCutchan 6-Jul-17 8:26am    
Quote from Windows Programming by Charles Petzold, "No one said it was easy". :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900