September 2004 - Posts
How to add references by automation
It's easy but I always forget the steps. I have to look in my code in order to remember. So here the steps:
1. Add a reference to VSLangProj. If you are writing a macro you don't need this step.
2. Add the using clause (C#)
using VSLangProj;
3. And use this function
public bool AddReference(EnvDTE.Project project, string reference)
{
VSProject proj = m_Project.Object as VSProject;
System.Diagnostics.Debug.Assert(proj != null); // This project is not a VSProject
if (proj == null)
return false;
try
{
proj.References.Add(reference);
}
catch (Exception ex)
{
string message = String.Format("Could not add {0}. \n Exception: {1}", reference, ex.Message);
System.Diagnostics.Trace.WriteLine(message);
return false;
}
return true;
}
In order to add a reference to a project you have to use proj.References.AddProject insted proj.References.Add.
If you wanna add a reference to an assembly that is in the GAC then pass just the dll name insted of the full path.
Inductive User Interface (IUI)
Since 2001, when the IUI guidelines were published there were a lot of comments about how useful is IUI.
A good summary about comments on IUI is on .Net Undocumented
In Microsoft Money, Win XP and Longhorn you can find real samples of IUI. If you wanna see how to build an IUI using windows forms take a look on these sample:
IUIs and Web-Style Navigation in Windows Forms, Part 1
IUIs and Web-Style Navigation in Windows Forms, Part 2
Give me a warning please !!
Actually it is common that programmers should switch between C# programming an C++ programming. This is my case, and when I switch to VC++ programming I really miss the C# compiler.
Today I spend 1 hour debugging (C++) because I wrote a code like this
CString Item::GetMessage()
{
CString sXml;
if (m_Info == NULL)
sXml.Format("%s", "Empty Item");
else
{
CString sXml;
sXml.Format("The Information is: %s", m_Info->GetInfo());
}
return sXml;
}
As you can see I redefined sXml, then my function always return "Empty Item" or "".
If you compile a similar code using C# compiler you are going to get an error ("A local variable named 'sXml' cannot be declared....").
So, C++ compiler please... Give me at least a warning !!
Community Technology Preview of VS Team System
It's available for MSDN subscribers
http://blogs.msdn.com/buckh/archive/2004/09/01/224384.aspx
More Posts