如何将发布为 Web 应用程序的模板与使用此包装器的 Web 应用程序集成?
How to integrate Template published as web applications with the web applications that use this wrapper?
我有以下情况:
我目前的项目是这样的:
master page
和 set of pages.aspx
从母版页继承布局。
现在我想做大规模。所以我想做的是:
两种类型的项目发布为two separate web applications
(松耦合):
- wrapper(主要通用模板,适用于所有其他网站
应用程序)替换(相同
中使用的母版页
应用程序),这个项目用作这样的框架或模板
:(Header,Footer)
, [(Sidebar(Menu),Body) dynamic according to the
web application which use the wrapper]
.
- 任何 Web 应用程序都会分两部分填充包装器(主体和
菜单)动态。
如何集成包装器和应使用此包装器的 Web 应用程序,并将它们都发布为两个单独的 Web 应用程序?
注意:
The main point , I don't want every change to the package(the wrapper)
to republish all the applications which use this package(the wrapper)
to take the update.
我过去曾使用 NuGet 包解决过这个问题。它们可以像您需要的那样复杂或简单。只需手动创建 .nuspec file, building it using the command line tool 并将其托管在文件系统(本地或网络)上,即可实现基本母版页布局。
将配置文件添加到模板项目的根目录 - 将其命名为 template.nuspec 并添加以下内容:
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>MyAppTemplate</id>
<version>1.0.0</version>
<description>A template web application</description>
<authors>Me or my company</authors>
</metadata>
<files>
<file src="Site.Master" target="content\Site.Master" />
<file src="Site.Master.cs" target="content\Site.Master.cs" />
<file src="Site.Master.designer.cs" target="content\Site.Master.designer.cs" />
</files>
</package>
请注意目标是 "content" - 这将在安装了 NuGet 包的项目根目录中删除母版页。您可能 还希望将母版页的命名空间更改为 $rootnamespace$
,因为这将执行 source code transformation,使母版页成为与你项目的其余部分。
从命令行,您可以调用 nuget.exe pack path\to\nuspec\file
这将导致创建 .nupkg
文件。对于本地开发,我通常将其放在 C:\NuGet\Local
中,尽管这可能是网络共享 \MyShare\InternalNuget
,或者如果您想更进一步,可以使用 ProGet or TeamCity 等解决方案。
然后在Visual Studio中你可以将它添加为包源:
Tools -> NuGet Package Manager -> Package Manager Settings -> Package Sources
单击加号并添加您的文件夹/unc 路径/url,然后您可以在任何其他项目中重复使用它。
作为一般规则,最好在创建项目时允许 NuGet 覆盖现有的 Site.Master,然后不要编辑文件,因为这允许您使用 NuGet 包集中管理更改版本控制。但是,如果您确实希望对项目进行特定更改,您可以这样做,您只需要记住不要让 NuGet 包在后续更新中覆盖项目版本。
您可以包含模板项目中的所有类型的文件。这包括 .ascx
用户控件、css 和 javascript 文件以及已编译或未编译的基页(继承自 System.Web.UI.Page
)。可能性是无止境。使用 <asp:contentplaceholder/>
和适当的 CSS,您可以通过用户控件在大多数项目中使用通用菜单,但仍然可以在不修改主模板的情况下将其替换为其他项目中更复杂的菜单。
编辑:
我想通过将包装器分成两部分可以达到预期的效果(至少对于相对简单的内容)。第一个是包含母版页的 NuGet 包。此母版页可以包含图表中页眉和页脚的 iframe、内容占位符和 css 以及常见样式的脚本标记和 javascript.
包装器的第二部分将是一个单独的应用程序,托管 iframe 的内容以及 .css 和 .js 文件。添加新的 javascript 库等重大更改仍需要更新母版页,但添加新功能或 css class 或更改品牌或徽标等小更改可以通过更改来完成包装文件并重新发布它。有点像托管您自己的简单 CDN。
母版页如下所示:
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="$rootnamespace$.SiteMaster" %>
<html>
<head runat="server">
<title><%: Page.Title %></title>
<link href="https://example.com/mywrapperapplication/styles/mywrapper.css" rel="stylesheet" />
</head>
<body>
<iframe src="https://example.com/mywrapperapplication/header.html" />
<form runat="server">
<asp:ContentPlaceHolder ID="MenuContent" runat="server"></asp:ContentPlaceHolder>
<asp:ContentPlaceHolder ID="BodyContent" runat="server"></asp:ContentPlaceHolder>
</form>
<iframe src="https://example.com/mywrapperapplication/footer.html" />
<script type="text/javascript" src="https://example.com/mywrapperapplication/scripts/mywrapper.js"></script>
</body>
</html>
然后您在 https://example.com/mywrapperapplication
部署了静态内容或简单应用程序
有 4 个(或更多)文件:
header.html --or aspx or whatever
footer.html
/scripts/mywrapper.js
/styles/mywrapper.css
您对这些文件中的任何一个所做的任何更改都将自动传播到包装的应用程序中,因为它们是从母版页链接的。如果您想添加一个额外的文件,您只需要重新发布包装的应用程序
<link href="https://example.com/mywrapperapplication/styles/mynewstyles.css" rel="stylesheet" />
为什么不将使用的应用程序发布为用户控件,并让母版页(您的包装器)以编程方式注入它们,类似于 DotNetNuke 所做的。
https://msdn.microsoft.com/en-us/library/c0az2h86.aspx
用户控件可以单独编译,不需要在更改包装器时重新编译。
我有以下情况:
我目前的项目是这样的:
master page
和 set of pages.aspx
从母版页继承布局。
现在我想做大规模。所以我想做的是:
两种类型的项目发布为two separate web applications
(松耦合):
- wrapper(主要通用模板,适用于所有其他网站
应用程序)替换(相同
中使用的母版页 应用程序),这个项目用作这样的框架或模板 :(Header,Footer)
,[(Sidebar(Menu),Body) dynamic according to the web application which use the wrapper]
.
- 任何 Web 应用程序都会分两部分填充包装器(主体和 菜单)动态。
如何集成包装器和应使用此包装器的 Web 应用程序,并将它们都发布为两个单独的 Web 应用程序?
注意:
The main point , I don't want every change to the package(the wrapper) to republish all the applications which use this package(the wrapper) to take the update.
我过去曾使用 NuGet 包解决过这个问题。它们可以像您需要的那样复杂或简单。只需手动创建 .nuspec file, building it using the command line tool 并将其托管在文件系统(本地或网络)上,即可实现基本母版页布局。
将配置文件添加到模板项目的根目录 - 将其命名为 template.nuspec 并添加以下内容:
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>MyAppTemplate</id>
<version>1.0.0</version>
<description>A template web application</description>
<authors>Me or my company</authors>
</metadata>
<files>
<file src="Site.Master" target="content\Site.Master" />
<file src="Site.Master.cs" target="content\Site.Master.cs" />
<file src="Site.Master.designer.cs" target="content\Site.Master.designer.cs" />
</files>
</package>
请注意目标是 "content" - 这将在安装了 NuGet 包的项目根目录中删除母版页。您可能 还希望将母版页的命名空间更改为 $rootnamespace$
,因为这将执行 source code transformation,使母版页成为与你项目的其余部分。
从命令行,您可以调用 nuget.exe pack path\to\nuspec\file
这将导致创建 .nupkg
文件。对于本地开发,我通常将其放在 C:\NuGet\Local
中,尽管这可能是网络共享 \MyShare\InternalNuget
,或者如果您想更进一步,可以使用 ProGet or TeamCity 等解决方案。
然后在Visual Studio中你可以将它添加为包源:
Tools -> NuGet Package Manager -> Package Manager Settings -> Package Sources
单击加号并添加您的文件夹/unc 路径/url,然后您可以在任何其他项目中重复使用它。
作为一般规则,最好在创建项目时允许 NuGet 覆盖现有的 Site.Master,然后不要编辑文件,因为这允许您使用 NuGet 包集中管理更改版本控制。但是,如果您确实希望对项目进行特定更改,您可以这样做,您只需要记住不要让 NuGet 包在后续更新中覆盖项目版本。
您可以包含模板项目中的所有类型的文件。这包括 .ascx
用户控件、css 和 javascript 文件以及已编译或未编译的基页(继承自 System.Web.UI.Page
)。可能性是无止境。使用 <asp:contentplaceholder/>
和适当的 CSS,您可以通过用户控件在大多数项目中使用通用菜单,但仍然可以在不修改主模板的情况下将其替换为其他项目中更复杂的菜单。
编辑:
我想通过将包装器分成两部分可以达到预期的效果(至少对于相对简单的内容)。第一个是包含母版页的 NuGet 包。此母版页可以包含图表中页眉和页脚的 iframe、内容占位符和 css 以及常见样式的脚本标记和 javascript.
包装器的第二部分将是一个单独的应用程序,托管 iframe 的内容以及 .css 和 .js 文件。添加新的 javascript 库等重大更改仍需要更新母版页,但添加新功能或 css class 或更改品牌或徽标等小更改可以通过更改来完成包装文件并重新发布它。有点像托管您自己的简单 CDN。
母版页如下所示:
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="$rootnamespace$.SiteMaster" %>
<html>
<head runat="server">
<title><%: Page.Title %></title>
<link href="https://example.com/mywrapperapplication/styles/mywrapper.css" rel="stylesheet" />
</head>
<body>
<iframe src="https://example.com/mywrapperapplication/header.html" />
<form runat="server">
<asp:ContentPlaceHolder ID="MenuContent" runat="server"></asp:ContentPlaceHolder>
<asp:ContentPlaceHolder ID="BodyContent" runat="server"></asp:ContentPlaceHolder>
</form>
<iframe src="https://example.com/mywrapperapplication/footer.html" />
<script type="text/javascript" src="https://example.com/mywrapperapplication/scripts/mywrapper.js"></script>
</body>
</html>
然后您在 https://example.com/mywrapperapplication
有 4 个(或更多)文件:
header.html --or aspx or whatever
footer.html
/scripts/mywrapper.js
/styles/mywrapper.css
您对这些文件中的任何一个所做的任何更改都将自动传播到包装的应用程序中,因为它们是从母版页链接的。如果您想添加一个额外的文件,您只需要重新发布包装的应用程序
<link href="https://example.com/mywrapperapplication/styles/mynewstyles.css" rel="stylesheet" />
为什么不将使用的应用程序发布为用户控件,并让母版页(您的包装器)以编程方式注入它们,类似于 DotNetNuke 所做的。
https://msdn.microsoft.com/en-us/library/c0az2h86.aspx
用户控件可以单独编译,不需要在更改包装器时重新编译。