containerize-aspnet-framework by github/awesome-copilot
npx skills add https://github.com/github/awesome-copilot --skill containerize-aspnet-framework根据以下容器化设置,对指定的 ASP.NET (.NET Framework) 项目进行容器化,仅专注于应用程序在 Windows Docker 容器中运行所需的更改。容器化过程应考虑此处指定的所有设置。
请记住: 这是一个 .NET Framework 应用程序,不是 .NET Core。容器化过程将与 .NET Core 应用程序不同。
提示的这一部分包含容器化 ASP.NET (.NET Framework) 应用程序所需的具体设置和配置。在运行此提示之前,请确保设置中已填写必要的信息。请注意,在许多情况下,只需要前几个设置。如果后面的设置不适用于正在容器化的项目,可以保留为默认值。
任何未指定的设置都将设置为默认值。默认值在 [方括号] 中提供。
要容器化的项目:
[项目名称(提供 .csproj 文件的路径)]要使用的 Windows Server SKU:
[Windows Server Core(默认)或 Windows Server Full]要使用的 Windows Server 版本:
[2022、2019 或 2016(默认 2022)]广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
Docker 镜像构建阶段使用的自定义基础镜像("None" 表示使用标准的 Microsoft 基础镜像):
[指定构建阶段使用的基础镜像(默认 None)]Docker 镜像运行阶段使用的自定义基础镜像("None" 表示使用标准的 Microsoft 基础镜像):
[指定运行阶段使用的基础镜像(默认 None)]必须在容器镜像中暴露的端口:
[例如,80][列出任何附加端口,或 "None"]容器应以其身份运行的用户账户:
[用户账户,或默认为 "ContainerUser"]必须在容器镜像中配置的 IIS 设置:
[列出任何特定的 IIS 设置,或 "None"]在构建容器镜像之前必须执行的自定义构建步骤:
[列出任何特定的构建步骤,或 "None"]在构建容器镜像之后必须执行的自定义构建步骤:
[列出任何特定的构建步骤,或 "None"]应在容器镜像的 GAC 中注册的 .NET 程序集:
[程序集名称和版本,或 "None"]必须复制到容器镜像并安装的 MSI:
[MSI 名称和版本,或 "None"]必须在容器镜像中注册的 COM 组件:
[COM 组件名称,或 "None"]必须添加到容器镜像的注册表键和值:
[注册表路径和值,或 "None"]必须在容器镜像中设置的环境变量:
[变量名和值,或 "Use defaults"]必须在容器镜像中安装的 Windows Server 角色和功能:
[角色/功能名称,或 "None"]需要复制到容器镜像的文件/目录:
[相对于项目根目录的路径,或 "None"][容器路径,或 "Not applicable"]要从容器化中排除的文件/目录:
[要排除的路径,或 "None"].dockerignore 文件中的模式(.dockerignore 已包含常见默认值;这些是附加模式):
[列出任何附加模式,或 "None"]健康检查端点:
[健康检查 URL 路径,或 "None"]健康检查间隔和超时:
[间隔和超时值,或 "Use defaults"]容器化项目必须遵循的其他说明:
[特定要求,或 "None"]需要解决的已知问题:
[描述任何已知问题,或 "None"]查看上述容器化设置以了解容器化要求
创建一个 progress.md 文件,用勾选标记跟踪更改
通过检查 TargetFrameworkVersion 元素,从项目的 .csproj 文件中确定 .NET Framework 版本
根据以下内容选择适当的 Windows Server 容器镜像:
确保所需的 NuGet 包已安装。如果缺少,请勿安装这些包。如果未安装,用户必须手动安装。如果未安装,请暂停执行此提示,并要求用户使用 Visual Studio NuGet 包管理器或 Visual Studio 包管理器控制台安装它们。需要以下包:
Microsoft.Configuration.ConfigurationBuilders.Environment修改 web.config 文件以添加配置构建器部分和设置,以便从环境变量读取应用程序设置和连接字符串:
在 configSections 中添加 ConfigBuilders 部分
在根目录中添加 configBuilders 部分
为 appSettings 和 connectionStrings 配置 EnvironmentConfigBuilder
示例模式:
<configSections>
<section name="configBuilders" type="System.Configuration.ConfigurationBuildersSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" restartOnExternalChanges="false" requirePermission="false" />
</configSections>
<configBuilders>
<builders>
<add name="Environment" type="Microsoft.Configuration.ConfigurationBuilders.EnvironmentConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.Environment" />
</builders>
</configBuilders>
<appSettings configBuilders="Environment">
<!-- 现有的应用程序设置 -->
</appSettings>
<connectionStrings configBuilders="Environment">
<!-- 现有的连接字符串 -->
</connectionStrings>
通过复制本提示末尾的参考 LogMonitorConfig.json 文件,在将创建 Dockerfile 的文件夹中创建一个 LogMonitorConfig.json 文件。文件内容不得修改,除非容器化设置中的说明另有规定,否则应与参考内容完全匹配。
Information 级别会产生不必要的噪音。在项目根目录中创建一个 Dockerfile 以容器化应用程序
mcr.microsoft.com/dotnet/framework/sdk 基础镜像mcr.microsoft.com/dotnet/framework/aspnet 基础镜像LogMonitorConfig.json 文件复制到容器中的目录(例如,C:\LogMonitor)ENTRYPOINT [ "C:\\LogMonitor\\LogMonitor.exe", "C:\\ServiceMonitor.exe", "w3svc" ]在项目根目录中创建一个 .dockerignore 文件,以从 Docker 镜像中排除不必要的文件。.dockerignore 文件必须至少包含以下元素以及容器化设置中指定的附加模式:
如果设置中指定了健康检查,则配置健康检查:
<None Include="Dockerfile" />一旦 Dockerfile 完成,确认 Docker 构建成功。使用以下命令构建 Docker 镜像:
docker build -t aspnet-app:latest .
如果构建失败,请查看错误消息并对 Dockerfile 或项目配置进行必要的调整。报告成功/失败。
维护一个具有以下结构的 progress.md 文件:
# 容器化进度
## 环境检测
- [ ] .NET Framework 版本检测(版本:___)
- [ ] Windows Server SKU 选择(SKU:___)
- [ ] Windows Server 版本选择(版本:___)
## 配置更改
- [ ] 为配置构建器修改 Web.config
- [ ] NuGet 包源配置(如果适用)
- [ ] 复制 LogMonitorConfig.json 并根据设置要求进行调整
## 容器化
- [ ] Dockerfile 创建
- [ ] .dockerignore 文件创建
- [ ] 使用 SDK 镜像创建构建阶段
- [ ] 为包恢复复制 sln、csproj、packages.config 以及(如果适用)NuGet.config
- [ ] 使用运行时镜像创建运行时阶段
- [ ] 非 root 用户配置
- [ ] 依赖项处理(GAC、MSI、COM、注册表、附加文件等)
- [ ] 健康检查配置(如果适用)
- [ ] 特殊要求实现
## 验证
- [ ] 审查容器化设置并确保满足所有要求
- [ ] Docker 构建成功
不要在步骤之间暂停确认。有条不紊地继续,直到应用程序被容器化且 Docker 构建成功。
在所有复选框被标记之前,您的工作尚未完成! 这包括成功构建 Docker 镜像并解决构建过程中出现的任何问题。
使用 Windows Server Core 基础镜像的 ASP.NET (.NET Framework) 应用程序的示例 Dockerfile。
# escape=`
# escape 指令将转义字符从 \ 更改为 `
# 这在 Windows Dockerfile 中特别有用,其中 \ 是路径分隔符
# ============================================================
# 阶段 1:构建和发布应用程序
# ============================================================
# 基础镜像 - 选择适当的 .NET Framework 版本和 Windows Server Core 版本
# 可能的标签包括:
# - 4.8.1-windowsservercore-ltsc2025 (Windows Server 2025)
# - 4.8-windowsservercore-ltsc2022 (Windows Server 2022)
# - 4.8-windowsservercore-ltsc2019 (Windows Server 2019)
# - 4.8-windowsservercore-ltsc2016 (Windows Server 2016)
# - 4.7.2-windowsservercore-ltsc2019 (Windows Server 2019)
# - 4.7.2-windowsservercore-ltsc2016 (Windows Server 2016)
# - 4.7.1-windowsservercore-ltsc2016 (Windows Server 2016)
# - 4.7-windowsservercore-ltsc2016 (Windows Server 2016)
# - 4.6.2-windowsservercore-ltsc2016 (Windows Server 2016)
# - 3.5-windowsservercore-ltsc2025 (Windows Server 2025)
# - 3.5-windowsservercore-ltsc2022 (Windows Server 2022)
# - 3.5-windowsservercore-ltsc2019 (Windows Server 2019)
# - 3.5-windowsservercore-ltsc2019 (Windows Server 2016)
# 使用 .NET Framework SDK 镜像构建应用程序
FROM mcr.microsoft.com/dotnet/framework/sdk:4.8-windowsservercore-ltsc2022 AS build
ARG BUILD_CONFIGURATION=Release
# 将默认 shell 设置为 PowerShell
SHELL ["powershell", "-command"]
WORKDIR /app
# 复制解决方案和项目文件
COPY YourSolution.sln .
COPY YourProject/*.csproj ./YourProject/
COPY YourOtherProject/*.csproj ./YourOtherProject/
# 复制 packages.config 文件
COPY YourProject/packages.config ./YourProject/
COPY YourOtherProject/packages.config ./YourOtherProject/
# 恢复 NuGet 包
RUN nuget restore YourSolution.sln
# 复制源代码
COPY . .
# 如果需要,在此处执行自定义预构建步骤
# 构建应用程序并将其发布到 C:\publish
RUN msbuild /p:Configuration=$BUILD_CONFIGURATION `
/p:WebPublishMethod=FileSystem `
/p:PublishUrl=C:\publish `
/p:DeployDefaultTarget=WebPublish
# 如果需要,在此处执行自定义后构建步骤
# ============================================================
# 阶段 2:最终运行时镜像
# ============================================================
# 基础镜像 - 选择适当的 .NET Framework 版本和 Windows Server Core 版本
# 可能的标签包括:
# - 4.8.1-windowsservercore-ltsc2025 (Windows Server 2025)
# - 4.8-windowsservercore-ltsc2022 (Windows Server 2022)
# - 4.8-windowsservercore-ltsc2019 (Windows Server 2019)
# - 4.8-windowsservercore-ltsc2016 (Windows Server 2016)
# - 4.7.2-windowsservercore-ltsc2019 (Windows Server 2019)
# - 4.7.2-windowsservercore-ltsc2016 (Windows Server 2016)
# - 4.7.1-windowsservercore-ltsc2016 (Windows Server 2016)
# - 4.7-windowsservercore-ltsc2016 (Windows Server 2016)
# - 4.6.2-windowsservercore-ltsc2016 (Windows Server 2016)
# - 3.5-windowsservercore-ltsc2025 (Windows Server 2025)
# - 3.5-windowsservercore-ltsc2022 (Windows Server 2022)
# - 3.5-windowsservercore-ltsc2019 (Windows Server 2019)
# - 3.5-windowsservercore-ltsc2019 (Windows Server 2016)
# 使用 .NET Framework ASP.NET 镜像运行应用程序
FROM mcr.microsoft.com/dotnet/framework/aspnet:4.8-windowsservercore-ltsc2022
# 将默认 shell 设置为 PowerShell
SHELL ["powershell", "-command"]
WORKDIR /inetpub/wwwroot
# 从构建阶段复制
COPY --from=build /publish .
# 添加应用程序所需的任何附加环境变量(根据需要取消注释和修改)
# ENV KEY=VALUE
# 安装 MSI 包(根据需要取消注释和修改)
# COPY ./msi-installers C:/Installers
# RUN Start-Process -Wait -FilePath 'msiexec.exe' -ArgumentList '/i', 'C:\Installers\your-package.msi', '/quiet', '/norestart'
# 安装自定义 Windows Server 角色和功能(根据需要取消注释和修改)
# RUN dism /Online /Enable-Feature /FeatureName:YOUR-FEATURE-NAME
# 添加附加的 Windows 功能(根据需要取消注释和修改)
# RUN Add-WindowsFeature Some-Windows-Feature; `
# Add-WindowsFeature Another-Windows-Feature
# 如果需要,安装 MSI 包(根据需要取消注释和修改)
# COPY ./msi-installers C:/Installers
# RUN Start-Process -Wait -FilePath 'msiexec.exe' -ArgumentList '/i', 'C:\Installers\your-package.msi', '/quiet', '/norestart'
# 如果需要,在 GAC 中注册程序集(根据需要取消注释和修改)
# COPY ./assemblies C:/Assemblies
# RUN C:\Windows\Microsoft.NET\Framework64\v4.0.30319\gacutil -i C:/Assemblies/YourAssembly.dll
# 如果需要,注册 COM 组件(根据需要取消注释和修改)
# COPY ./com-components C:/Components
# RUN regsvr32 /s C:/Components/YourComponent.dll
# 如果需要,添加注册表键(根据需要取消注释和修改)
# RUN New-Item -Path 'HKLM:\Software\YourApp' -Force; `
# Set-ItemProperty -Path 'HKLM:\Software\YourApp' -Name 'Setting' -Value 'Value'
# 如果需要,配置 IIS 设置(根据需要取消注释和修改)
# RUN Import-Module WebAdministration; `
# Set-ItemProperty 'IIS:\AppPools\DefaultAppPool' -Name somePropertyName -Value 'SomePropertyValue'; `
# Set-ItemProperty 'IIS:\Sites\Default Web Site' -Name anotherPropertyName -Value 'AnotherPropertyValue'
# 暴露必要的端口 - 默认情况下,IIS 使用端口 80
EXPOSE 80
# EXPOSE 443 # 如果使用 HTTPS,请取消注释
# 从 microsoft/windows-container-tools 仓库复制 LogMonitor
WORKDIR /LogMonitor
RUN curl -fSLo LogMonitor.exe https://github.com/microsoft/windows-container-tools/releases/download/v2.1.1/LogMonitor.exe
# 从本地文件复制 LogMonitorConfig.json
COPY LogMonitorConfig.json .
# 设置非管理员用户
USER ContainerUser
# 覆盖容器的默认入口点以利用 LogMonitor
ENTRYPOINT [ "C:\\LogMonitor\\LogMonitor.exe", "C:\\ServiceMonitor.exe", "w3svc" ]
注意: 根据容器化设置中的特定要求定制此模板。
调整此示例 Dockerfile 时:
YourSolution.sln、YourProject.csproj 等替换为您的实际文件名AS stage-name 语法为每个阶段命名--from=stage-name 从上一个阶段复制文件LogMonitorConfig.json 文件应在项目根目录中创建。它用于配置 LogMonitor 工具,该工具监视容器中的日志。此文件的内容应完全如下所示,以确保正确的日志记录功能:
{
"LogConfig": {
"sources": [
{
"type": "EventLog",
"startAtOldestRecord": true,
"eventFormatMultiLine": false,
"channels": [
{
"name": "system",
"level": "Warning"
},
{
"name": "application",
"level": "Error"
}
]
},
{
"type": "File",
"directory": "c:\\inetpub\\logs",
"filter": "*.log",
"includeSubdirectories": true,
"includeFileNames": false
},
{
"type": "ETW",
"eventFormatMultiLine": false,
"providers": [
{
"providerName": "IIS: WWW Server",
"providerGuid": "3A2A4E84-4C21-4981-AE10-3FDA0D9B0F83",
"level": "Information"
},
{
"providerName": "Microsoft-Windows-IIS-Logging",
"providerGuid": "7E8AD27F-B271-4EA2-A783-A47BDE29143B",
"level": "Information"
}
]
}
]
}
}
每周安装次数
7.3K
仓库
GitHub 星标
26.7K
首次出现
2026年2月25日
安全审计
安装于
codex7.2K
gemini-cli7.2K
opencode7.2K
cursor7.2K
github-copilot7.1K
kimi-cli7.1K
Containerize the ASP.NET (.NET Framework) project specified in the containerization settings below, focusing exclusively on changes required for the application to run in a Windows Docker container. Containerization should consider all settings specified here.
REMEMBER: This is a .NET Framework application, not .NET Core. The containerization process will be different from that of a .NET Core application.
This section of the prompt contains the specific settings and configurations required for containerizing the ASP.NET (.NET Framework) application. Prior to running this prompt, ensure that the settings are filled out with the necessary information. Note that in many cases, only the first few settings are required. Later settings can be left as defaults if they do not apply to the project being containerized.
Any settings that are not specified will be set to default values. The default values are provided in [square brackets].
Project to containerize:
[ProjectName (provide path to .csproj file)]Windows Server SKU to use:
[Windows Server Core (Default) or Windows Server Full]Windows Server version to use:
[2022, 2019, or 2016 (Default 2022)]Custom base image for the build stage of the Docker image ("None" to use standard Microsoft base image):
[Specify base image to use for build stage (Default None)]Custom base image for the run stage of the Docker image ("None" to use standard Microsoft base image):
[Specify base image to use for run stage (Default None)]Ports that must be exposed in the container image:
[e.g., 80][List any additional ports, or "None"]User account the container should run as:
[User account, or default to "ContainerUser"]IIS settings that must be configured in the container image:
[List any specific IIS settings, or "None"]Custom build steps that must be performed before building the container image:
[List any specific build steps, or "None"]Custom build steps that must be performed after building the container image:
[List any specific build steps, or "None"].NET assemblies that should be registered in the GAC in the container image:
[Assembly name and version, or "None"]MSIs that must be copied to the container image and installed:
[MSI names and versions, or "None"]COM components that must be registered in the container image:
[COM component names, or "None"]Registry keys and values that must be added to the container image:
[Registry paths and values, or "None"]Environment variables that must be set in the container image:
[Variable names and values, or "Use defaults"]Windows Server roles and features that must be installed in the container image:
[Role/feature names, or "None"]Files/directories that need to be copied to the container image:
[Paths relative to project root, or "None"][Container paths, or "Not applicable"]Files/directories to exclude from containerization:
[Paths to exclude, or "None"].dockerignore file (.dockerignore will already have common defaults; these are additional patterns):
[List any additional patterns, or "None"]Health check endpoint:
[Health check URL path, or "None"]Health check interval and timeout:
[Interval and timeout values, or "Use defaults"]Other instructions that must be followed to containerize the project:
[Specific requirements, or "None"]Known issues to address:
[Describe any known issues, or "None"]Review the containerization settings above to understand the containerization requirements
Create a progress.md file to track changes with check marks
Determine the .NET Framework version from the project's .csproj file by checking the TargetFrameworkVersion element
Select the appropriate Windows Server container image based on:
Ensure that required NuGet packages are installed. DO NOT install these if they are missing. If they are not installed, the user must install them manually. If they are not installed, pause executing this prompt and ask the user to install them using the Visual Studio NuGet Package Manager or Visual Studio package manager console. The following packages are required:
Microsoft.Configuration.ConfigurationBuilders.EnvironmentModify the file to add configuration builders section and settings to read app settings and connection strings from environment variables:
<None Include="Dockerfile" />confirm that Docker build succeeds once the Dockerfile is completed. Use the following command to build the Docker image:
docker build -t aspnet-app:latest .
If the build fails, review the error messages and make necessary adjustments to the Dockerfile or project configuration. Report success/failure.
Maintain a progress.md file with the following structure:
# Containerization Progress
## Environment Detection
- [ ] .NET Framework version detection (version: ___)
- [ ] Windows Server SKU selection (SKU: ___)
- [ ] Windows Server version selection (Version: ___)
## Configuration Changes
- [ ] Web.config modifications for configuration builders
- [ ] NuGet package source configuration (if applicable)
- [ ] Copy LogMonitorConfig.json and adjust if required by settings
## Containerization
- [ ] Dockerfile creation
- [ ] .dockerignore file creation
- [ ] Build stage created with SDK image
- [ ] sln, csproj, packages.config, and (if applicable) NuGet.config copied for package restore
- [ ] Runtime stage created with runtime image
- [ ] Non-root user configuration
- [ ] Dependency handling (GAC, MSI, COM, registry, additional files, etc.)
- [ ] Health check configuration (if applicable)
- [ ] Special requirements implementation
## Verification
- [ ] Review containerization settings and make sure that all requirements are met
- [ ] Docker build success
Do not pause for confirmation between steps. Continue methodically until the application has been containerized and Docker build succeeds.
YOU ARE NOT DONE UNTIL ALL CHECKBOXES ARE MARKED! This includes building the Docker image successfully and addressing any issues that arise during the build process.
An example Dockerfile for an ASP.NET (.NET Framework) application using a Windows Server Core base image.
# escape=`
# The escape directive changes the escape character from \ to `
# This is especially useful in Windows Dockerfiles where \ is the path separator
# ============================================================
# Stage 1: Build and publish the application
# ============================================================
# Base Image - Select the appropriate .NET Framework version and Windows Server Core version
# Possible tags include:
# - 4.8.1-windowsservercore-ltsc2025 (Windows Server 2025)
# - 4.8-windowsservercore-ltsc2022 (Windows Server 2022)
# - 4.8-windowsservercore-ltsc2019 (Windows Server 2019)
# - 4.8-windowsservercore-ltsc2016 (Windows Server 2016)
# - 4.7.2-windowsservercore-ltsc2019 (Windows Server 2019)
# - 4.7.2-windowsservercore-ltsc2016 (Windows Server 2016)
# - 4.7.1-windowsservercore-ltsc2016 (Windows Server 2016)
# - 4.7-windowsservercore-ltsc2016 (Windows Server 2016)
# - 4.6.2-windowsservercore-ltsc2016 (Windows Server 2016)
# - 3.5-windowsservercore-ltsc2025 (Windows Server 2025)
# - 3.5-windowsservercore-ltsc2022 (Windows Server 2022)
# - 3.5-windowsservercore-ltsc2019 (Windows Server 2019)
# - 3.5-windowsservercore-ltsc2019 (Windows Server 2016)
# Uses the .NET Framework SDK image for building the application
FROM mcr.microsoft.com/dotnet/framework/sdk:4.8-windowsservercore-ltsc2022 AS build
ARG BUILD_CONFIGURATION=Release
# Set the default shell to PowerShell
SHELL ["powershell", "-command"]
WORKDIR /app
# Copy the solution and project files
COPY YourSolution.sln .
COPY YourProject/*.csproj ./YourProject/
COPY YourOtherProject/*.csproj ./YourOtherProject/
# Copy packages.config files
COPY YourProject/packages.config ./YourProject/
COPY YourOtherProject/packages.config ./YourOtherProject/
# Restore NuGet packages
RUN nuget restore YourSolution.sln
# Copy source code
COPY . .
# Perform custom pre-build steps here, if needed
# Build and publish the application to C:\publish
RUN msbuild /p:Configuration=$BUILD_CONFIGURATION `
/p:WebPublishMethod=FileSystem `
/p:PublishUrl=C:\publish `
/p:DeployDefaultTarget=WebPublish
# Perform custom post-build steps here, if needed
# ============================================================
# Stage 2: Final runtime image
# ============================================================
# Base Image - Select the appropriate .NET Framework version and Windows Server Core version
# Possible tags include:
# - 4.8.1-windowsservercore-ltsc2025 (Windows Server 2025)
# - 4.8-windowsservercore-ltsc2022 (Windows Server 2022)
# - 4.8-windowsservercore-ltsc2019 (Windows Server 2019)
# - 4.8-windowsservercore-ltsc2016 (Windows Server 2016)
# - 4.7.2-windowsservercore-ltsc2019 (Windows Server 2019)
# - 4.7.2-windowsservercore-ltsc2016 (Windows Server 2016)
# - 4.7.1-windowsservercore-ltsc2016 (Windows Server 2016)
# - 4.7-windowsservercore-ltsc2016 (Windows Server 2016)
# - 4.6.2-windowsservercore-ltsc2016 (Windows Server 2016)
# - 3.5-windowsservercore-ltsc2025 (Windows Server 2025)
# - 3.5-windowsservercore-ltsc2022 (Windows Server 2022)
# - 3.5-windowsservercore-ltsc2019 (Windows Server 2019)
# - 3.5-windowsservercore-ltsc2019 (Windows Server 2016)
# Uses the .NET Framework ASP.NET image for running the application
FROM mcr.microsoft.com/dotnet/framework/aspnet:4.8-windowsservercore-ltsc2022
# Set the default shell to PowerShell
SHELL ["powershell", "-command"]
WORKDIR /inetpub/wwwroot
# Copy from build stage
COPY --from=build /publish .
# Add any additional environment variables needed for your application (uncomment and modify as needed)
# ENV KEY=VALUE
# Install MSI packages (uncomment and modify as needed)
# COPY ./msi-installers C:/Installers
# RUN Start-Process -Wait -FilePath 'msiexec.exe' -ArgumentList '/i', 'C:\Installers\your-package.msi', '/quiet', '/norestart'
# Install custom Windows Server roles and features (uncomment and modify as needed)
# RUN dism /Online /Enable-Feature /FeatureName:YOUR-FEATURE-NAME
# Add additional Windows features (uncomment and modify as needed)
# RUN Add-WindowsFeature Some-Windows-Feature; `
# Add-WindowsFeature Another-Windows-Feature
# Install MSI packages if needed (uncomment and modify as needed)
# COPY ./msi-installers C:/Installers
# RUN Start-Process -Wait -FilePath 'msiexec.exe' -ArgumentList '/i', 'C:\Installers\your-package.msi', '/quiet', '/norestart'
# Register assemblies in GAC if needed (uncomment and modify as needed)
# COPY ./assemblies C:/Assemblies
# RUN C:\Windows\Microsoft.NET\Framework64\v4.0.30319\gacutil -i C:/Assemblies/YourAssembly.dll
# Register COM components if needed (uncomment and modify as needed)
# COPY ./com-components C:/Components
# RUN regsvr32 /s C:/Components/YourComponent.dll
# Add registry keys if needed (uncomment and modify as needed)
# RUN New-Item -Path 'HKLM:\Software\YourApp' -Force; `
# Set-ItemProperty -Path 'HKLM:\Software\YourApp' -Name 'Setting' -Value 'Value'
# Configure IIS settings if needed (uncomment and modify as needed)
# RUN Import-Module WebAdministration; `
# Set-ItemProperty 'IIS:\AppPools\DefaultAppPool' -Name somePropertyName -Value 'SomePropertyValue'; `
# Set-ItemProperty 'IIS:\Sites\Default Web Site' -Name anotherPropertyName -Value 'AnotherPropertyValue'
# Expose necessary ports - By default, IIS uses port 80
EXPOSE 80
# EXPOSE 443 # Uncomment if using HTTPS
# Copy LogMonitor from the microsoft/windows-container-tools repository
WORKDIR /LogMonitor
RUN curl -fSLo LogMonitor.exe https://github.com/microsoft/windows-container-tools/releases/download/v2.1.1/LogMonitor.exe
# Copy LogMonitorConfig.json from local files
COPY LogMonitorConfig.json .
# Set non-administrator user
USER ContainerUser
# Override the container's default entry point to take advantage of the LogMonitor
ENTRYPOINT [ "C:\\LogMonitor\\LogMonitor.exe", "C:\\ServiceMonitor.exe", "w3svc" ]
Note: Customize this template based on the specific requirements in the containerization settings.
When adapting this example Dockerfile:
YourSolution.sln, YourProject.csproj, etc. with your actual file namesAS stage-name syntax gives each stage a name--from=stage-name to copy files from a previous stageThe LogMonitorConfig.json file should be created in the root of the project directory. It is used to configure the LogMonitor tool, which monitors logs in the container. The contents of this file should look exactly like this to ensure proper logging functionality:
{
"LogConfig": {
"sources": [
{
"type": "EventLog",
"startAtOldestRecord": true,
"eventFormatMultiLine": false,
"channels": [
{
"name": "system",
"level": "Warning"
},
{
"name": "application",
"level": "Error"
}
]
},
{
"type": "File",
"directory": "c:\\inetpub\\logs",
"filter": "*.log",
"includeSubdirectories": true,
"includeFileNames": false
},
{
"type": "ETW",
"eventFormatMultiLine": false,
"providers": [
{
"providerName": "IIS: WWW Server",
"providerGuid": "3A2A4E84-4C21-4981-AE10-3FDA0D9B0F83",
"level": "Information"
},
{
"providerName": "Microsoft-Windows-IIS-Logging",
"providerGuid": "7E8AD27F-B271-4EA2-A783-A47BDE29143B",
"level": "Information"
}
]
}
]
}
}
Weekly Installs
7.3K
Repository
GitHub Stars
26.7K
First Seen
Feb 25, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykWarn
Installed on
codex7.2K
gemini-cli7.2K
opencode7.2K
cursor7.2K
github-copilot7.1K
kimi-cli7.1K
97,600 周安装
web.configAdd ConfigBuilders section in configSections
Add configBuilders section in the root
Configure EnvironmentConfigBuilder for both appSettings and connectionStrings
Example pattern:
<configSections>
<section name="configBuilders" type="System.Configuration.ConfigurationBuildersSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" restartOnExternalChanges="false" requirePermission="false" />
</configSections>
<configBuilders>
<builders>
<add name="Environment" type="Microsoft.Configuration.ConfigurationBuilders.EnvironmentConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.Environment" />
</builders>
</configBuilders>
<appSettings configBuilders="Environment">
<!-- existing app settings -->
</appSettings>
<connectionStrings configBuilders="Environment">
<!-- existing connection strings -->
</connectionStrings>
Create a LogMonitorConfig.json file in the folder where the Dockerfile will be created by copying the reference LogMonitorConfig.json file at the end of this prompt. The file's contents MUST NOT not be modified and should match the reference content exactly unless instructions in containerization settings specify otherwise.
Information level for EventLog sources will cause unnecessary noise.Create a Dockerfile in the root of the project directory to containerize the application
mcr.microsoft.com/dotnet/framework/sdk base image unless a custom base image is specified in the settings filemcr.microsoft.com/dotnet/framework/aspnet base image unless a custom base image is specified in the settings fileLogMonitorConfig.json file to a directory in the container (e.g., C:\LogMonitor)ENTRYPOINT [ "C:\\LogMonitor\\LogMonitor.exe", "C:\\ServiceMonitor.exe", "w3svc" ]Create a .dockerignore file in the root of the project directory to exclude unnecessary files from the Docker image. The .dockerignore file MUST include at least the following elements as well as additional patterns as specified in the containerization settings:
Configure health checks if specified in the settings: