Winforms Designer: is it possible to programmatically achieve project variables?

I work in C # Winforms, .net 4.0 and develop some development-time components. My goal is for the designer to look for the specific file located in it (either the project directory or the output directory).

In any case, do I need to find the values โ€‹โ€‹of the following variables from the code?

(Outpath) (ProjectDir)

+4
source share
1 answer

Well, it's not that difficult if you can access the EnvDTE80.DTE2 representing your instance of Visual Studio. In fact, if dte is your instance of DTE2, it is simple as:

foreach (Project prj in dte.Solution.Projects) { MessageBox.Show(Path.GetDirectoryName(prj.FullName)); MessageBox.Show(prj.ConfigurationManager.ActiveConfiguration.Properties.Item("OutputPath").Value.ToString()); } 

Getting a DTE2 object is easy if you are writing an add-in, since this is the first parameter passed to OnConnection (the add-in project wizard automatically writes code that puts it in the _applicationObject variable in the Connect class).

If you have only a component, you can get the Site property, which implements ISite, which comes from IServiceProvider, and ask him to get DTE2. If compo is your component:

  dte = (DTE2)compo.Site.GetService(typeof(DTE2)); 
+1
source

All Articles