开发者

Silverlight multi project template. How can I automatically link the Silverlight project with the web project?

I've managed to create a multi project template for our Silverlight solutions by using 开发者_如何学运维the VS2010 SDK and a TemplateWizard. My question is how can I automatically link the Silverlight project with the web project? I have two templates: One for the host web project and one for the SL project. The trouble is that I cannot get hold of the Silverlight project GUID in order to set it in the SilverlightApplicationList tag contained within the web project file. I have tried setting the Silverlight project GUID via a TemplateWizard but the GUID always gets regenerated when the the Silverlight project is created.


I've found a solution to this be running the Microsoft.VisualStudio.ServiceModel.DomainServices.Tools.dll through .NET Reflector. I figured the existing Silverlight templates must be using some mechanism to link the SL project to the web project. I've added the following code to my RunFinished method on my IWizard implementation that is called by the root project template:

public void RunFinished()
{
    IVsHierarchy hierarchy;
    IVsHierarchy hierarchy2;

    Project webProject = this.GetProject(this._webProjectName);
    Project slProject = this.GetProject(this._slProjectName);

    EnvDTE.Properties properties = webProject.Properties;
    ProjectItem aspxTestPage = this.GetAspxTestPage(webProject);
    if (aspxTestPage != null)
    {
        properties.Item("WebApplication.StartPageUrl").Value = aspxTestPage.Name;
        properties.Item("WebApplication.DebugStartAction").Value = 1;
    }

    IServiceProvider sp = this._dte2 as IServiceProvider;
    IVsSolution service = null;
    using (ServiceProvider provider2 = new ServiceProvider(sp))
    {
        service = provider2.GetService(typeof(IVsSolution)) as IVsSolution;
    }
    if (((service.GetProjectOfUniqueName(webProject.UniqueName, out hierarchy) == 0) && (hierarchy != null)) && (service.GetProjectOfUniqueName(slProject.UniqueName, out hierarchy2) == 0))
    {
        (hierarchy as IVsSilverlightProjectConsumer).LinkToSilverlightProject("ClientBin", true, false, hierarchy2 as IVsSilverlightProject);
    }
}

This code works a treat.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜