蓝色天空.知识 · 实践 · 创造
我的收藏
在线代码实验室

离线校验手动发布四步骤、10 个必备 DLL 清单、App_Data/*.sdf 保护过滤与 dotnet publish 迁移

PYTHONWindows x64、CPython 3.12.14 离线 ASP.NET WebPages / Razor 语义验证器(本机未启动 IIS / IIS Express / WebMatrix 宿主环境)。explore-webpages-publish.py
explore-webpages-publish.py126 行
"""Offline ASP.NET semantic verification lab for Chapter 16 (webpages-publish)."""
import json

VERSION = "CPython 3.12.14 offline ASP.NET WebPages/Core semantic verifier (IIS/WebMatrix absent)"


def case_manual_publish_four_steps():
    steps = [
        "1.verify_host_aspnet_4_0_or_4_5",
        "2.copy_web_folders_excluding_prod_data",
        "3.copy_required_bin_dlls",
        "4.handle_app_data_sdf_safely",
    ]
    expected = {"step_count": 4, "first_step": steps[0], "last_step": steps[-1]}
    actual = {"step_count": len(steps), "first_step": steps[0], "last_step": steps[-1]}
    return {
        "name": "manual_publish_four_steps",
        "summary": "核对不依赖 WebMatrix(如 FTP 手动上传)发布 Web Pages 应用程序的四个步骤顺序",
        "expected": expected,
        "actual": actual,
        "passed": actual == expected,
    }


def case_bin_dll_manifest_verification():
    required_dlls = [
        "Microsoft.Web.Infrastructure.dll",
        "NuGet.Core.dll",
        "System.Web.Helpers.dll",
        "System.Web.Razor.dll",
        "System.Web.WebPages.Administration.dll",
        "System.Web.WebPages.Deployment.dll",
        "System.Web.WebPages.dll",
        "System.Web.WebPages.Razor.dll",
        "WebMatrix.Data.dll",
        "WebMatrix.WebData.dll",
    ]
    expected = {
        "dll_count": 10,
        "all_end_with_dll": True,
        "webmatrix_webdata_normalized": "WebMatrix.WebData.dll",
    }
    actual = {
        "dll_count": len(required_dlls),
        "all_end_with_dll": all(d.endswith(".dll") for d in required_dlls),
        "webmatrix_webdata_normalized": required_dlls[-1],
    }
    return {
        "name": "bin_dll_manifest_verification",
        "summary": "核对 bin 文件夹所需的 10 个核心程序集清单(并补全原列表末项 WebMatrix.WebData 的 .dll 扩展名)",
        "expected": expected,
        "actual": actual,
        "passed": actual == expected,
    }


def case_appdata_prod_database_protection():
    local_files = [
        "Default.cshtml",
        "Shared/_Layout.cshtml",
        "Images/logo.png",
        "bin/System.Web.WebPages.dll",
        "App_Data/SmallBakery.sdf",
    ]

    def select_files_for_upload(files, overwrite_data=False):
        return [
            f for f in files
            if overwrite_data or not (f.startswith("App_Data/") and f.endswith(".sdf"))
        ]

    safe_upload = select_files_for_upload(local_files, overwrite_data=False)
    expected = {
        "excluded_sdf": True,
        "uploaded_count": 4,
        "empty_sdf_rule": "如需首次部署结构,应清空测试行后再上传空 .sdf 文件",
    }
    actual = {
        "excluded_sdf": "App_Data/SmallBakery.sdf" not in safe_upload,
        "uploaded_count": len(safe_upload),
        "empty_sdf_rule": "如需首次部署结构,应清空测试行后再上传空 .sdf 文件",
    }
    return {
        "name": "appdata_prod_database_protection",
        "summary": "验证发布清单过滤 App_Data/*.sdf 测试数据库,避免覆盖远程生产数据",
        "expected": expected,
        "actual": actual,
        "passed": actual == expected,
    }


def case_modern_dotnet_publish_migration():
    modern_cmd = "dotnet publish -c Release -o ./publish"
    ef_migration_cmd = "dotnet ef database update"
    expected = {
        "uses_dotnet_publish": True,
        "uses_ef_migrations": True,
        "sql_ce_eol": True,
    }
    actual = {
        "uses_dotnet_publish": modern_cmd.startswith("dotnet publish"),
        "uses_ef_migrations": ef_migration_cmd.startswith("dotnet ef"),
        "sql_ce_eol": True,
    }
    return {
        "name": "modern_dotnet_publish_migration",
        "summary": "核对现代 ASP.NET Core 使用 dotnet publish 与 EF Core Migrations 替代手工复制 DLL 与 .sdf 文件",
        "expected": expected,
        "actual": actual,
        "passed": actual == expected,
    }


def main():
    cases = [
        case_manual_publish_four_steps(),
        case_bin_dll_manifest_verification(),
        case_appdata_prod_database_protection(),
        case_modern_dotnet_publish_migration(),
    ]
    print(json.dumps({"version": VERSION, "cases": cases}, ensure_ascii=False, indent=2))


if __name__ == "__main__":
    main()
本例需在 Windows x64、CPython 3.12.14 离线 ASP.NET WebPages / Razor 语义验证器(本机未启动 IIS / IIS Express / WebMatrix 宿主环境)。 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程

运行环境:Windows x64、CPython 3.12.14 离线 ASP.NET WebPages / Razor 语义验证器(本机未启动 IIS / IIS Express / WebMatrix 宿主环境)。

入口文件:projects/aspnet-webpages-publish-lab/explore-webpages-publish.py

本地运行步骤快速上手
  1. 点击上方“保存源码”保存为 explore-webpages-publish.py,或下载右侧课程工程包。
  2. 确认本地已准备 Windows x64、CPython 3.12.14 离线 ASP.NET WebPages / Razor 语义验证器(本机未启动 IIS / IIS Express / WebMatrix 宿主环境)。。
  3. 按对应章节命令执行,结合正文核对实际输出。
附件与关联工程包下载

下载课程关联工程包:ASP.NET

课程关联工程包(登记关联55章) · 含当前章节或实例 · mbskycom202612a2794.zip

下载课程关联工程包:ASP.NET

课程关联工程包(登记关联1章) · 含当前章节或实例 · mbskycom202612a2844.zip
SITE SEARCH

搜索教程、工具与资讯

热门搜索

JavaScriptJSON格式化正则表达式AI 编程AI 翻译AI导航专题标签
Esc 关闭

欢迎登录蓝色天空网

使用会员账号,继续你的学习