开发者

Getting the current project directory from experimental instance of visual studio 2010?

I'm currently implementing uml validation http://msdn.microsoft.com/en-us/library/ee329482.aspx,

when i debug, it opens a new experimental instance of visual studio for me to validate uml diagrams.

Is there a way to get the path of project directory selected by the user when the experimental instance of visual studio is running??

To be more clear,

project A - has VSIX and Class library components to validate uml validation. These class Library components are added to VSIX as MEF components

when i debug Project A -> new experimental instance of VS will open-> Then creating a new project (ctrl+shift+N)-> select modelling project-> browse to the directory (to store the modelling p开发者_如何学Goroject)->Name the Project as "MYMODEL" -> then press OK

Now, In my Project A i need the path of MYMODEL. Can you please tell me how do i get that path??

Thanks in Advance,


This is a bit roundabout, but works. You need references to EnvDTE and Microsoft.VisualStudio.Shell.Immutable.10.0 as well as the usual bits.

using System.ComponentModel.Composition;
using Microsoft.VisualStudio.ArchitectureTools.Extensibility;
using Microsoft.VisualStudio.ArchitectureTools.Extensibility.Uml;
using Microsoft.VisualStudio.Modeling.Validation;
using Microsoft.VisualStudio.Uml.AuxiliaryConstructs;

namespace Validation
{
  public class MyValidationExtensions
  {
    [Import]
    public Microsoft.VisualStudio.Shell.SVsServiceProvider ServiceProvider { get; set; }

    [Export(typeof(System.Action<ValidationContext, object>))]
    [ValidationMethod(
     ValidationCategories.Open
     | ValidationCategories.Menu)]
    public void ValidateClassNames
      (ValidationContext context,
      // This type determines what elements 
      // will be validated by this method:
       IModel elementToValidate)
    {
      IModelStore store = elementToValidate.GetModelStore();
      EnvDTE.DTE dte = ServiceProvider.GetService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;
      //dynamic projects = dte.ActiveSolutionProjects;

      foreach (EnvDTE.Project project in dte.Solution.Projects)
      {
        IModelingProject mp = project as IModelingProject;
        if (mp.Store == store)
        {
          System.Windows.Forms.MessageBox.Show(project.FullName);
        }
      }

    }
    // Add more validation methods for different element types.
  }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜