1
---
2
name: containerize-aspnet-framework
3
description: 'Containerize an ASP.NET .NET Framework project by creating Dockerfile and .dockerfile files customized for the project.'
4
---
5
6
# ASP.NET .NET Framework Containerization Prompt
7
8
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.
9
10
**REMEMBER:** This is a .NET Framework application, not .NET Core. The containerization process will be different from that of a .NET Core application.
11
12
## Containerization Settings
13
14
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.
15
16
Any settings that are not specified will be set to default values. The default values are provided in `[square brackets]`.
17
18
### Basic Project Information
19
1. Project to containerize:
20
- `[ProjectName (provide path to .csproj file)]`
21
22
2. Windows Server SKU to use:
23
- `[Windows Server Core (Default) or Windows Server Full]`
24
25
3. Windows Server version to use:
26
- `[2022, 2019, or 2016 (Default 2022)]`
27
28
4. Custom base image for the build stage of the Docker image ("None" to use standard Microsoft base image):
29
- `[Specify base image to use for build stage (Default None)]`
30
31
5. Custom base image for the run stage of the Docker image ("None" to use standard Microsoft base image):
32
- `[Specify base image to use for run stage (Default None)]`
33
34
### Container Configuration
35
1. Ports that must be exposed in the container image:
36
- Primary HTTP port: `[e.g., 80]`
37
- Additional ports: `[List any additional ports, or "None"]`
38
39
2. User account the container should run as:
40
- `[User account, or default to "ContainerUser"]`
41
42
3. IIS settings that must be configured in the container image:
43
- `[List any specific IIS settings, or "None"]`
44
45
### Build configuration
46
1. Custom build steps that must be performed before building the container image:
47
- `[List any specific build steps, or "None"]`
48
49
2. Custom build steps that must be performed after building the container image:
50
- `[List any specific build steps, or "None"]`
51
52
### Dependencies
53
1. .NET assemblies that should be registered in the GAC in the container image:
54
- `[Assembly name and version, or "None"]`
55
56
2. MSIs that must be copied to the container image and installed:
57
- `[MSI names and versions, or "None"]`
58
59
3. COM components that must be registered in the container image:
60
- `[COM component names, or "None"]`
61
62
### System Configuration
63
1. Registry keys and values that must be added to the container image:
64
- `[Registry paths and values, or "None"]`
65
66
2. Environment variables that must be set in the container image:
67
- `[Variable names and values, or "Use defaults"]`
68
69
3. Windows Server roles and features that must be installed in the container image:
70
- `[Role/feature names, or "None"]`
71
72
### File System
73
1. Files/directories that need to be copied to the container image:
74
- `[Paths relative to project root, or "None"]`
75
- Target location in container: `[Container paths, or "Not applicable"]`
76
77
2. Files/directories to exclude from containerization:
78
- `[Paths to exclude, or "None"]`
79
80
### .dockerignore Configuration
81
1. Patterns to include in the `.dockerignore` file (.dockerignore will already have common defaults; these are additional patterns):
82
- Additional patterns: `[List any additional patterns, or "None"]`
83
84
### Health Check Configuration
85
1. Health check endpoint:
86
- `[Health check URL path, or "None"]`
87
88
2. Health check interval and timeout:
89
- `[Interval and timeout values, or "Use defaults"]`
90
91
### Additional Instructions
92
1. Other instructions that must be followed to containerize the project:
93
- `[Specific requirements, or "None"]`
94
95
2. Known issues to address:
96
- `[Describe any known issues, or "None"]`
97
98
## Scope
99
100
- ✅ App configuration modification to ensure config builders are used to read app settings and connection strings from the environment variables
101
- ✅ Dockerfile creation and configuration for an ASP.NET application
102
- ✅ Specifying multiple stages in the Dockerfile to build/publish the application and copy the output to the final image
103
- ✅ Configuration of Windows container platform compatibility (Windows Server Core or Full)
104
- ✅ Proper handling of dependencies (GAC assemblies, MSIs, COM components)
105
- ❌ No infrastructure setup (assumed to be handled separately)
106
- ❌ No code changes beyond those required for containerization
107
108
## Execution Process
109
110
1. Review the containerization settings above to understand the containerization requirements
111
2. Create a `progress.md` file to track changes with check marks
112
3. Determine the .NET Framework version from the project's .csproj file by checking the `TargetFrameworkVersion` element
113
4. Select the appropriate Windows Server container image based on:
114
- The .NET Framework version detected from the project
115
- The Windows Server SKU specified in containerization settings (Core or Full)
116
- The Windows Server version specified in containerization settings (2016, 2019, or 2022)
117
- Windows Server Core tags can be found at: https://github.com/microsoft/dotnet-framework-docker/blob/main/README.aspnet.md#full-tag-listing
118
5. 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:
119
- `Microsoft.Configuration.ConfigurationBuilders.Environment`
120
6. Modify the `web.config` file to add configuration builders section and settings to read app settings and connection strings from environment variables:
121
- Add ConfigBuilders section in configSections
122
- Add configBuilders section in the root
123
- Configure EnvironmentConfigBuilder for both appSettings and connectionStrings
124
- Example pattern:
125
```xml
126
<configSections>
127
<section name="configBuilders" type="System.Configuration.ConfigurationBuildersSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" restartOnExternalChanges="false" requirePermission="false" />
128
</configSections>
129
<configBuilders>
130
<builders>
131
<add name="Environment" type="Microsoft.Configuration.ConfigurationBuilders.EnvironmentConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.Environment" />
132
</builders>
133
</configBuilders>
134
<appSettings configBuilders="Environment">
135
<!-- existing app settings -->
136
</appSettings>
137
<connectionStrings configBuilders="Environment">
138
<!-- existing connection strings -->
139
</connectionStrings>
140
```
141
7. 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.
142
- In particular, make sure the level of issues to be logged is not changed as using `Information` level for EventLog sources will cause unnecessary noise.
143
8. Create a Dockerfile in the root of the project directory to containerize the application
144
- The Dockerfile should use multiple stages:
145
- Build stage: Use a Windows Server Core image to build the application
146
- The build stage MUST use a `mcr.microsoft.com/dotnet/framework/sdk` base image unless a custom base image is specified in the settings file
147
- Copy sln, csproj, and packages.config files first
148
- Copy NuGet.config if one exists and configure any private feeds
149
- Restore NuGet packages
150
- Then, copy the rest of the source code and build and publish the application to C:\publish using MSBuild
151
- Final stage: Use the selected Windows Server image to run the application
152
- The final stage MUST use a `mcr.microsoft.com/dotnet/framework/aspnet` base image unless a custom base image is specified in the settings file
153
- Copy the `LogMonitorConfig.json` file to a directory in the container (e.g., C:\LogMonitor)
154
- Download LogMonitor.exe from the Microsoft repository to the same directory
155
- The correct LogMonitor.exe URL is: https://github.com/microsoft/windows-container-tools/releases/download/v2.1.1/LogMonitor.exe
156
- Set the working directory to C:\inetpub\wwwroot
157
- Copy the published output from the build stage (in C:\publish) to the final image
158
- Set the container's entry point to run LogMonitor.exe with ServiceMonitor.exe to monitor the IIS service
159
- `ENTRYPOINT [ "C:\\LogMonitor\\LogMonitor.exe", "C:\\ServiceMonitor.exe", "w3svc" ]`
160
- Be sure to consider all requirements in the containerization settings:
161
- Windows Server SKU and version
162
- Exposed ports
163
- User account for container
164
- IIS settings
165
- GAC assembly registration
166
- MSI installation
167
- COM component registration
168
- Registry keys
169
- Environment variables
170
- Windows roles and features
171
- File/directory copying
172
- Model the Dockerfile after the example provided at the end of this prompt, but ensure it is customized to the specific project requirements and settings.
173
- **IMPORTANT:** Use a Windows Server Core base image unless the user has **specifically requested** a full Windows Server image in the settings file
174
9. 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:
175
- packages/
176
- bin/
177
- obj/
178
- .dockerignore
179
- Dockerfile
180
- .git/
181
- .github/
182
- .vs/
183
- .vscode/
184
- **/node_modules/
185
- *.user
186
- *.suo
187
- **/.DS_Store
188
- **/Thumbs.db
189
- Any additional patterns specified in the containerization settings
190
10. Configure health checks if specified in the settings:
191
- Add HEALTHCHECK instruction to Dockerfile if health check endpoint is provided
192
11. Add the dockerfile to the project by adding the following item to the project file: `<None Include="Dockerfile" />`
193
12. Mark tasks as completed: [ ] → [✓]
194
13. Continue until all tasks are complete and Docker build succeeds
195
196
## Build and Runtime Verification
197
198
confirm that Docker build succeeds once the Dockerfile is completed. Use the following command to build the Docker image:
199
200
```bash
201
docker build -t aspnet-app:latest .
202
```
203
204
If the build fails, review the error messages and make necessary adjustments to the Dockerfile or project configuration. Report success/failure.
205
206
## Progress Tracking
207
208
Maintain a `progress.md` file with the following structure:
209
```markdown
210
# Containerization Progress
211
212
## Environment Detection
213
- [ ] .NET Framework version detection (version: ___)
214
- [ ] Windows Server SKU selection (SKU: ___)
215
- [ ] Windows Server version selection (Version: ___)
216
217
## Configuration Changes
218
- [ ] Web.config modifications for configuration builders
219
- [ ] NuGet package source configuration (if applicable)
220
- [ ] Copy LogMonitorConfig.json and adjust if required by settings
221
222
## Containerization
223
- [ ] Dockerfile creation
224
- [ ] .dockerignore file creation
225
- [ ] Build stage created with SDK image
226
- [ ] sln, csproj, packages.config, and (if applicable) NuGet.config copied for package restore
227
- [ ] Runtime stage created with runtime image
228
- [ ] Non-root user configuration
229
- [ ] Dependency handling (GAC, MSI, COM, registry, additional files, etc.)
230
- [ ] Health check configuration (if applicable)
231
- [ ] Special requirements implementation
232
233
## Verification
234
- [ ] Review containerization settings and make sure that all requirements are met
235
- [ ] Docker build success
236
```
237
238
Do not pause for confirmation between steps. Continue methodically until the application has been containerized and Docker build succeeds.
239
240
**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.
241
242
## Reference Materials
243
244
### Example Dockerfile
245
246
An example Dockerfile for an ASP.NET (.NET Framework) application using a Windows Server Core base image.
247
248
```dockerfile
249
# escape=`
250
# The escape directive changes the escape character from \ to `
251
# This is especially useful in Windows Dockerfiles where \ is the path separator
252
253
# ============================================================
254
# Stage 1: Build and publish the application
255
# ============================================================
256
257
# Base Image - Select the appropriate .NET Framework version and Windows Server Core version
258
# Possible tags include:
259
# - 4.8.1-windowsservercore-ltsc2025 (Windows Server 2025)
260
# - 4.8-windowsservercore-ltsc2022 (Windows Server 2022)
261
# - 4.8-windowsservercore-ltsc2019 (Windows Server 2019)
262
# - 4.8-windowsservercore-ltsc2016 (Windows Server 2016)
263
# - 4.7.2-windowsservercore-ltsc2019 (Windows Server 2019)
264
# - 4.7.2-windowsservercore-ltsc2016 (Windows Server 2016)
265
# - 4.7.1-windowsservercore-ltsc2016 (Windows Server 2016)
266
# - 4.7-windowsservercore-ltsc2016 (Windows Server 2016)
267
# - 4.6.2-windowsservercore-ltsc2016 (Windows Server 2016)
268
# - 3.5-windowsservercore-ltsc2025 (Windows Server 2025)
269
# - 3.5-windowsservercore-ltsc2022 (Windows Server 2022)
270
# - 3.5-windowsservercore-ltsc2019 (Windows Server 2019)
271
# - 3.5-windowsservercore-ltsc2019 (Windows Server 2016)
272
# Uses the .NET Framework SDK image for building the application
273
FROM mcr.microsoft.com/dotnet/framework/sdk:4.8-windowsservercore-ltsc2022 AS build
274
ARG BUILD_CONFIGURATION=Release
275
276
# Set the default shell to PowerShell
277
SHELL ["powershell", "-command"]
278
279
WORKDIR /app
280
281
# Copy the solution and project files
282
COPY YourSolution.sln .
283
COPY YourProject/*.csproj ./YourProject/
284
COPY YourOtherProject/*.csproj ./YourOtherProject/
285
286
# Copy packages.config files
287
COPY YourProject/packages.config ./YourProject/
288
COPY YourOtherProject/packages.config ./YourOtherProject/
289
290
# Restore NuGet packages
291
RUN nuget restore YourSolution.sln
292
293
# Copy source code
294
COPY . .
295
296
# Perform custom pre-build steps here, if needed
297
298
# Build and publish the application to C:\publish
299
RUN msbuild /p:Configuration=$BUILD_CONFIGURATION `
300
/p:WebPublishMethod=FileSystem `
301
/p:PublishUrl=C:\publish `
302
/p:DeployDefaultTarget=WebPublish
303
304
# Perform custom post-build steps here, if needed
305
306
# ============================================================
307
# Stage 2: Final runtime image
308
# ============================================================
309
310
# Base Image - Select the appropriate .NET Framework version and Windows Server Core version
311
# Possible tags include:
312
# - 4.8.1-windowsservercore-ltsc2025 (Windows Server 2025)
313
# - 4.8-windowsservercore-ltsc2022 (Windows Server 2022)
314
# - 4.8-windowsservercore-ltsc2019 (Windows Server 2019)
315
# - 4.8-windowsservercore-ltsc2016 (Windows Server 2016)
316
# - 4.7.2-windowsservercore-ltsc2019 (Windows Server 2019)
317
# - 4.7.2-windowsservercore-ltsc2016 (Windows Server 2016)
318
# - 4.7.1-windowsservercore-ltsc2016 (Windows Server 2016)
319
# - 4.7-windowsservercore-ltsc2016 (Windows Server 2016)
320
# - 4.6.2-windowsservercore-ltsc2016 (Windows Server 2016)
321
# - 3.5-windowsservercore-ltsc2025 (Windows Server 2025)
322
# - 3.5-windowsservercore-ltsc2022 (Windows Server 2022)
323
# - 3.5-windowsservercore-ltsc2019 (Windows Server 2019)
324
# - 3.5-windowsservercore-ltsc2019 (Windows Server 2016)
325
# Uses the .NET Framework ASP.NET image for running the application
326
FROM mcr.microsoft.com/dotnet/framework/aspnet:4.8-windowsservercore-ltsc2022
327
328
# Set the default shell to PowerShell
329
SHELL ["powershell", "-command"]
330
331
WORKDIR /inetpub/wwwroot
332
333
# Copy from build stage
334
COPY --from=build /publish .
335
336
# Add any additional environment variables needed for your application (uncomment and modify as needed)
337
# ENV KEY=VALUE
338
339
# Install MSI packages (uncomment and modify as needed)
340
# COPY ./msi-installers C:/Installers
341
# RUN Start-Process -Wait -FilePath 'msiexec.exe' -ArgumentList '/i', 'C:\Installers\your-package.msi', '/quiet', '/norestart'
342
343
# Install custom Windows Server roles and features (uncomment and modify as needed)
344
# RUN dism /Online /Enable-Feature /FeatureName:YOUR-FEATURE-NAME
345
346
# Add additional Windows features (uncomment and modify as needed)
347
# RUN Add-WindowsFeature Some-Windows-Feature; `
348
# Add-WindowsFeature Another-Windows-Feature
349
350
# Install MSI packages if needed (uncomment and modify as needed)
351
# COPY ./msi-installers C:/Installers
352
# RUN Start-Process -Wait -FilePath 'msiexec.exe' -ArgumentList '/i', 'C:\Installers\your-package.msi', '/quiet', '/norestart'
353
354
# Register assemblies in GAC if needed (uncomment and modify as needed)
355
# COPY ./assemblies C:/Assemblies
356
# RUN C:\Windows\Microsoft.NET\Framework64\v4.0.30319\gacutil -i C:/Assemblies/YourAssembly.dll
357
358
# Register COM components if needed (uncomment and modify as needed)
359
# COPY ./com-components C:/Components
360
# RUN regsvr32 /s C:/Components/YourComponent.dll
361
362
# Add registry keys if needed (uncomment and modify as needed)
363
# RUN New-Item -Path 'HKLM:\Software\YourApp' -Force; `
364
# Set-ItemProperty -Path 'HKLM:\Software\YourApp' -Name 'Setting' -Value 'Value'
365
366
# Configure IIS settings if needed (uncomment and modify as needed)
367
# RUN Import-Module WebAdministration; `
368
# Set-ItemProperty 'IIS:\AppPools\DefaultAppPool' -Name somePropertyName -Value 'SomePropertyValue'; `
369
# Set-ItemProperty 'IIS:\Sites\Default Web Site' -Name anotherPropertyName -Value 'AnotherPropertyValue'
370
371
# Expose necessary ports - By default, IIS uses port 80
372
EXPOSE 80
373
# EXPOSE 443 # Uncomment if using HTTPS
374
375
# Copy LogMonitor from the microsoft/windows-container-tools repository
376
WORKDIR /LogMonitor
377
RUN curl -fSLo LogMonitor.exe https://github.com/microsoft/windows-container-tools/releases/download/v2.1.1/LogMonitor.exe
378
379
# Copy LogMonitorConfig.json from local files
380
COPY LogMonitorConfig.json .
381
382
# Set non-administrator user
383
USER ContainerUser
384
385
# Override the container's default entry point to take advantage of the LogMonitor
386
ENTRYPOINT [ "C:\\LogMonitor\\LogMonitor.exe", "C:\\ServiceMonitor.exe", "w3svc" ]
387
```
388
389
## Adapting this Example
390
391
**Note:** Customize this template based on the specific requirements in the containerization settings.
392
393
When adapting this example Dockerfile:
394
395
1. Replace `YourSolution.sln`, `YourProject.csproj`, etc. with your actual file names
396
2. Adjust the Windows Server and .NET Framework versions as needed
397
3. Modify the dependency installation steps based on your requirements and remove any unnecessary ones
398
4. Add or remove stages as needed for your specific workflow
399
400
## Notes on Stage Naming
401
402
- The `AS stage-name` syntax gives each stage a name
403
- Use `--from=stage-name` to copy files from a previous stage
404
- You can have multiple intermediate stages that aren't used in the final image
405
406
### LogMonitorConfig.json
407
408
The 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:
409
```json
410
{
411
"LogConfig": {
412
"sources": [
413
{
414
"type": "EventLog",
415
"startAtOldestRecord": true,
416
"eventFormatMultiLine": false,
417
"channels": [
418
{
419
"name": "system",
420
"level": "Warning"
421
},
422
{
423
"name": "application",
424
"level": "Error"
425
}
426
]
427
},
428
{
429
"type": "File",
430
"directory": "c:\\inetpub\\logs",
431
"filter": "*.log",
432
"includeSubdirectories": true,
433
"includeFileNames": false
434
},
435
{
436
"type": "ETW",
437
"eventFormatMultiLine": false,
438
"providers": [
439
{
440
"providerName": "IIS: WWW Server",
441
"providerGuid": "3A2A4E84-4C21-4981-AE10-3FDA0D9B0F83",
442
"level": "Information"
443
},
444
{
445
"providerName": "Microsoft-Windows-IIS-Logging",
446
"providerGuid": "7E8AD27F-B271-4EA2-A783-A47BDE29143B",
447
"level": "Information"
448
}
449
]
450
}
451
]
452
}
453
}
454
```
455