簡體   English   中英

Silverlight 多項目模板。 如何自動將 Silverlight 項目與 web 項目鏈接?

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

通過使用 VS2010 SDK 和 TemplateWizard,我設法為我們的 Silverlight 解決方案創建了一個多項目模板。 我的問題是如何自動將 Silverlight 項目與 web 項目鏈接? 我有兩個模板:一個用於主機 web 項目,一個用於 SL 項目。 問題是我無法獲取 Silverlight 項目 GUID 以便將其設置在 web 項目文件中包含的 SilverlightApplicationList 標記中。 我嘗試通過 TemplateWizard 設置 Silverlight 項目 GUID,但在創建 Silverlight 項目時,GUID 總是會重新生成。

我找到了一個解決方案,通過 .NET Reflector 運行 Microsoft.VisualStudio.ServiceModel.DomainServices.Tools.dll。 我認為現有的 Silverlight 模板必須使用某種機制將 SL 項目鏈接到 web 項目。 我已在根項目模板調用的 IWizard 實現上的 RunFinished 方法中添加了以下代碼:

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);
    }
}

這段代碼很有效。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM