Hi Johndoe,
From your description, you're developing asp.net web control and use the
DnvDTE namespace's interfaces
===================
objProject.DTE.ActiveDocument.Path;
===================
to get the current active project's(or items in it)'s path. But find the
result is not what you expected, yes?
As for this problem, it is because the ActiveDocument or the Active Project
get from the DNVDTE's inferfaces is not actually the active one if there're
more than one VS.NET ide opened. It will return the first opened VS.NET
instance. So this means works only if we open only one vs.net instance when
developing.
You can also see another approach in the following link:
http://blogs.msdn.com/mszcool/archive/2004/06/30/169793.aspx And though the DnvDTE's fix behavior is like the above I mentioend, we can
use some COM interop means to workaround it so as to get the actual active
project in VS.NET ide, here is a demo I've made and also tested on myside,
please have a look to see whether it help. Thanks.
=======================================
namespace MyWebControlLib
{
public class TestControlDesigner : System.Web.UI.Design.ControlDesigner
{
public override string GetDesignTimeHtml()
{
string html = "";
try
{
string strMoniker = "!VisualStudio.DTE.7.1:" +
System.Diagnostics.Process.GetCurrentProcess().Id.ToString();
EnvDTE.DTE dte =(EnvDTE.DTE)GetMSDEVFromGIT(strMoniker);
html = "<br>" + dte.ActiveDocument.FullName;
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
return html;
}
[DllImport("ole32.dll")]
public static extern int GetRunningObjectTable(int reserved, out
UCOMIRunningObjectTable prot);
[DllImport("ole32.dll")]
public static extern int CreateBindCtx(int reserved, out UCOMIBindCtx
ppbc);
public object GetMSDEVFromGIT(string strProgID)
{
UCOMIRunningObjectTable prot;
UCOMIEnumMoniker pMonkEnum;
GetRunningObjectTable(0,out prot);
prot.EnumRunning(out pMonkEnum);
pMonkEnum.Reset();
int fetched;
UCOMIMoniker []pmon = new UCOMIMoniker[1];
while(pMonkEnum.Next(1, pmon, out fetched) == 0)
{
UCOMIBindCtx pCtx;
CreateBindCtx(0, out pCtx);
string str;
pmon[0].GetDisplayName(pCtx,null,out str);
if(str == strProgID)
{
object objReturnObject;
prot.GetObject(pmon[0],out objReturnObject);
object ide = (object)objReturnObject;
return ide;
}
}
return null;
}
}
[DefaultProperty("Text"),
ToolboxData("<{0}:TestControl runat=server></{0}:TestControl>"),
Designer(typeof(TestControlDesigner))]
public class TestControl : System.Web.UI.WebControls.WebControl
{
private string text;
[Bindable(true),
Category("Appearance"),
DefaultValue("")]
public string Text
{
get
{
return text;
}
set
{
text = value;
}
}
protected override void Render(HtmlTextWriter output)
{
output.Write("<center><font size='20'>Hello World!</font></center>");
}
}
}
================================================
Regards,
Steven Cheng
Microsoft Online Support
Get Secure!
www.microsoft.com/security (This posting is provided "AS IS", with no warranties, and confers no
rights.)
Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx