Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,23 @@ node_modules/

# Ignore package.json and package-lock.json
package.json
package-lock.json
package-lock.json

# .NET build artifacts
bin/
obj/
*.user
*.suo
*.cache
*.dll
*.exe
*.pdb
*.vspscc
*.vssscc
.vs/
.vscode/
*.log

# Generated WinGet configuration files
WinGetConfigApplier/generated-*.yaml
WinGetConfigApplier/*-output.yaml
196 changes: 196 additions & 0 deletions IMPLEMENTATION_SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
# WinGet Configuration Applier - Implementation Summary

## Overview
Successfully implemented a C# console application that parses JSON configuration files and programmatically applies WinGet configurations for unattended software installations.

## Implementation Details

### Project Structure
```
WinGetConfigApplier/
├── Models/
│ └── AppConfiguration.cs # Data models for JSON configuration
├── Services/
│ ├── ConfigurationValidator.cs # Configuration validation logic
│ ├── Logger.cs # Console logging implementation
│ ├── WinGetConfigurationBuilder.cs # YAML generation from JSON
│ └── WinGetInstaller.cs # WinGet command execution
├── Program.cs # Main application entry point
├── apps-config.json # Sample configuration file
├── README.md # Detailed documentation
└── WinGetConfigApplier.csproj # .NET project file
```

### Key Features Implemented

#### 1. JSON Configuration Parser
- **Models**: Created strongly-typed C# classes for configuration
- `AppConfiguration`: Root configuration object
- `Application`: Individual application definition
- `InstallOptions`: Installation preferences
- `ConfigurationSettings`: Global settings

#### 2. Configuration Validation
- Validates required fields (id, name, source)
- Checks for empty application lists
- Validates configuration settings
- Provides detailed error messages with field-level feedback

#### 3. Logging System
- Color-coded console output:
- White: Information
- Yellow: Warnings
- Red: Errors
- Gray: Debug
- Configurable log levels: Debug, Information, Warning, Error
- Timestamped log entries
- Clean, professional output format

#### 4. WinGet Configuration Builder
- Generates valid WinGet DSC YAML from JSON
- Supports OS version assertions
- Developer Mode enablement option
- Proper YAML formatting with schema reference
- Sanitizes IDs for YAML compatibility

#### 5. WinGet Integration
- Programmatic execution of WinGet commands
- Asynchronous process handling
- Real-time output streaming
- Error capture and reporting
- Exit code handling
- WinGet availability checking

#### 6. Error Handling
- Comprehensive try-catch blocks
- JSON parsing error handling
- File I/O error handling
- Process execution error handling
- User-friendly error messages
- Non-zero exit codes for failures

### Sample JSON Configuration
```json
{
"applications": [
{
"id": "Microsoft.VisualStudioCode",
"name": "Visual Studio Code",
"source": "winget",
"installOptions": {
"silent": true,
"acceptPackageAgreements": true
},
"description": "Install Visual Studio Code"
}
],
"configuration": {
"minOsVersion": "10.0.22631",
"enableDeveloperMode": true,
"logLevel": "Information"
}
}
```

### Generated WinGet YAML
The application generates standard WinGet DSC YAML files compatible with:
- WinGet DSC schema 0.2
- Microsoft.Windows.Developer resources
- Microsoft.WinGet.DSC resources

## Testing Results

### Validation Testing
✅ Successfully detects missing required fields
✅ Properly validates empty application lists
✅ Correctly identifies configuration errors
✅ Provides clear error messages

### YAML Generation Testing
✅ Generates valid WinGet DSC YAML
✅ Includes all required sections (assertions, resources)
✅ Properly formats package entries
✅ Adds schema references

### Application Flow Testing
✅ Help command works correctly
✅ Configuration file loading successful
✅ JSON parsing works properly
✅ Graceful handling when WinGet unavailable
✅ Proper exit codes (0 for success, 1 for errors)

## Security Scan Results
- **CodeQL Analysis**: ✅ No vulnerabilities detected
- **Code Review**: ✅ No issues found

## Documentation
- Comprehensive README in WinGetConfigApplier directory
- Updated main repository README
- Inline code comments for complex logic
- XML documentation comments on public APIs
- Usage examples and command-line help

## Command-Line Interface
```bash
# Display help
dotnet run -- --help

# Use default configuration
dotnet run

# Use custom configuration and output files
dotnet run -- myconfig.json output.yaml
```

## Technical Specifications
- **Framework**: .NET 9.0
- **Language**: C# 12
- **Target OS**: Windows 10/11 (10.0.22631+)
- **Build**: Both Debug and Release configurations
- **Output**: Console application (cross-platform capable)

## Build Commands
```bash
# Debug build
dotnet build

# Release build
dotnet build -c Release

# Publish standalone executable
dotnet publish -c Release -r win-x64 --self-contained
```

## Future Enhancement Opportunities
While the current implementation meets all requirements, potential enhancements could include:
- Unit tests for services and validation
- Support for multiple configuration sources
- Configuration file templates
- Dry-run mode
- Progress reporting during installation
- Configuration file merging
- Application dependency resolution

## Compliance
✅ Meets all problem statement requirements:
- ✅ C# console application
- ✅ Parses JSON file with application identifiers
- ✅ Supports installation options
- ✅ Programmatically applies WinGet configuration
- ✅ Unattended (silent) installations
- ✅ Basic validation
- ✅ Logging
- ✅ Failure handling

## Files Modified/Created
1. **Created**: WinGetConfigApplier/Program.cs
2. **Created**: WinGetConfigApplier/Models/AppConfiguration.cs
3. **Created**: WinGetConfigApplier/Services/ConfigurationValidator.cs
4. **Created**: WinGetConfigApplier/Services/Logger.cs
5. **Created**: WinGetConfigApplier/Services/WinGetConfigurationBuilder.cs
6. **Created**: WinGetConfigApplier/Services/WinGetInstaller.cs
7. **Created**: WinGetConfigApplier/WinGetConfigApplier.csproj
8. **Created**: WinGetConfigApplier/apps-config.json
9. **Created**: WinGetConfigApplier/README.md
10. **Modified**: README.md (added section about C# app)
11. **Modified**: .gitignore (added C# build artifacts)
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ If you find this project helpful, please give it a star 🌟
## Table of Contents

- [Installation](#installation)
- [WinGet Configuration Applier (C# Console App)](#winget-configuration-applier-c-console-app)
- [What's Included](#whats-included)
- [Documentation](#documentation)

Expand All @@ -26,6 +27,47 @@ winget configure -f winget-config.yaml
if (Test-Path 'post-install.ps1') { Remove-Item -Path 'post-install.ps1' -Force }; Invoke-WebRequest -Uri 'https://raw.githubusercontent.com/devexlead/onboarding-winget/refs/heads/main/post-install.ps1' -OutFile 'post-install.ps1' -Headers @{"Cache-Control"="no-cache"}; .\post-install.ps1
```

## WinGet Configuration Applier (C# Console App)

A C# console application that parses a JSON file containing application identifiers and installation options, then programmatically applies a WinGet configuration to perform unattended (silent) software installations.

### Features

- ✅ **JSON Configuration**: Define applications to install in a simple JSON format
- ✅ **Validation**: Built-in configuration validation with detailed error messages
- ✅ **Logging**: Comprehensive logging with configurable log levels
- ✅ **Error Handling**: Robust error handling and failure reporting
- ✅ **WinGet Integration**: Generates WinGet DSC YAML configuration and applies it programmatically
- ✅ **Silent Installation**: Supports unattended installations

### Quick Start

1. Navigate to the `WinGetConfigApplier` directory
2. Customize `apps-config.json` with your desired applications
3. Run the application:

```bash
dotnet run
```

For detailed documentation, see [WinGetConfigApplier/README.md](WinGetConfigApplier/README.md)

### Building

```bash
cd WinGetConfigApplier
dotnet build -c Release
```

### Publishing a Standalone Executable

```bash
cd WinGetConfigApplier
dotnet publish -c Release -r win-x64 --self-contained
```

The executable will be in `bin/Release/net9.0/win-x64/publish/`

## What's Included

Here’s the list of applications that will be installed (based on the `winget-config.yaml`):
Expand Down
41 changes: 41 additions & 0 deletions WinGetConfigApplier/Models/AppConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
namespace WinGetConfigApplier.Models;

/// <summary>
/// Represents the root configuration object
/// </summary>
public class AppConfiguration
{
public List<Application> Applications { get; set; } = new();
public ConfigurationSettings Configuration { get; set; } = new();
}

/// <summary>
/// Represents an application to be installed
/// </summary>
public class Application
{
public string Id { get; set; } = string.Empty;
public string Name { get; set; } = string.Empty;
public string Source { get; set; } = "winget";
public InstallOptions InstallOptions { get; set; } = new();
public string Description { get; set; } = string.Empty;
}

/// <summary>
/// Represents installation options for an application
/// </summary>
public class InstallOptions
{
public bool Silent { get; set; } = true;
public bool AcceptPackageAgreements { get; set; } = true;
}

/// <summary>
/// Represents global configuration settings
/// </summary>
public class ConfigurationSettings
{
public string MinOsVersion { get; set; } = "10.0.22631";
public bool EnableDeveloperMode { get; set; } = false;
public string LogLevel { get; set; } = "Information";
}
Loading