4

I'm working in C# Winforms, .net 4.0, and am designing some design-time components. My goal is to have the designer look for a specific file that resides in (either the project dir or the output dir).

Is there anyway for me to find the values of the following variables from code?

(Outpath) (ProjectDir)

4

1 回答 1

1

好吧,如果您可以访问代表您的 Visual Studio 实例的 EnvDTE80.DTE2,这并不难。事实上,如果 dte 是您的 DTE2 实例,它很简单:

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

如果您正在编写加载项,则获取 DTE2 对象很容易,因为它是传递给 OnConnection 的第一个参数(加载项项目的向导会自动编写代码,将其放入 Connect 类的 _applicationObject 变量中)。

如果你只有组件,你可以获取Site属性,它实现了ISite,它是从IServiceProvider派生的,并要求它获取DTE2。如果 compo 是您的组件:

   dte = (DTE2)compo.Site.GetService(typeof(DTE2));
于 2012-09-11T10:55:09.090 回答