Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jun 25, 2025

This PR introduces a comprehensive MSBuild-based template system that automatically generates all the boilerplate files needed for a DeviceRunners test app, eliminating the need for developers to manually create and maintain platform-specific files.

🔧 Bootstrap Infrastructure

  • DeviceRunners.VisualRunners.Maui.Bootstrap: MSBuild-based template processing system
  • Drop-in NuGet package solution - no attributes or configuration required
  • Auto-detects MAUI projects and generates platform files automatically

🏗️ Generated Files

The bootstrap system automatically creates platform-specific entry points:

  • Android: MainActivity.cs, MainApplication.cs
  • iOS: Program.cs, AppDelegate.cs, Info.plist (via PartialAppManifest)
  • Windows: App.xaml.cs, App.xaml, app.manifest, Package.appxmanifest
  • macOS Catalyst: Program.cs, AppDelegate.cs, Info.plist (via PartialAppManifest)

📝 Simple Usage

Developers can now create a device test app by simply:

  1. Adding a reference to DeviceRunners.VisualRunners.Maui.Bootstrap
  2. Setting standard MSBuild properties:
    <ApplicationTitle>My Test App</ApplicationTitle>
    <ApplicationId>com.company.mytestapp</ApplicationId>

The system automatically detects MAUI projects and generates all necessary files.

⚙️ Configuration

Uses standard MSBuild properties:

  • ApplicationTitle - Application display name
  • ApplicationId - Bundle/package identifier
  • RootNamespace - Code namespace

🧪 Testing & Validation

  • Successfully builds complete test apps across all platforms
  • Integrated with existing DeviceTestingKitApp.DeviceTests sample
  • Template processing with proper namespace replacement

✅ Benefits

  1. Simplified Architecture: Uses MSBuild template processing instead of complex source generators
  2. Zero Configuration: Auto-detects MAUI projects with test frameworks
  3. Drop-in Solution: Just add NuGet package reference
  4. Maintainable: Simple string replacement templates easy to modify
  5. Platform Complete: Handles all MAUI target platforms correctly

🔄 Evolution Notes

This PR initially started as a Roslyn source generator but evolved into a simpler, more maintainable MSBuild template system after realizing that complex code generation wasn't necessary - simple file templating with string replacement achieves the same goal with much less complexity.

💡 Key Technical Decisions

  • MSBuild over Roslyn: Simpler to maintain and debug than source generators
  • Template Files: Stored in NuGet package build/templates/ folder
  • Auto-Detection: No attributes needed - detects MAUI projects automatically
  • Standard Properties: Uses existing MSBuild properties instead of custom attributes
  • Batched Processing: Efficient template processing using MSBuild item batching

This represents a major step toward making device testing as simple as installing a NuGet package.

Addressing #88.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI changed the title [WIP] Create a Roslyn source generator that generates all the files for a test app Create Roslyn source generator for automatic DeviceRunners test app generation Jun 25, 2025
Copilot AI requested a review from mattleibow June 25, 2025 19:35
Copilot finished work on behalf of mattleibow June 25, 2025 19:35
Copy link
Owner

@mattleibow mattleibow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need the sample-sourcegen-test project. Update the DeviceTestingKitApp.DeviceTests project to use this new source gen.

Also, no need for the new TestApp, since the sample test is the test app.

…ceTests to use source generator

Co-authored-by: mattleibow <[email protected]>
Copy link
Contributor Author

Copilot AI commented Jun 25, 2025

We don't need the sample-sourcegen-test project. Update the DeviceTestingKitApp.DeviceTests project to use this new source gen.

Also, no need for the new TestApp, since the sample test is the t...

Done. Removed the sample-sourcegen-test project and updated the existing DeviceTestingKitApp.DeviceTests project to use the source generator instead. Commit afd68d7.

Copilot AI requested a review from mattleibow June 25, 2025 20:45
Copilot finished work on behalf of mattleibow June 25, 2025 20:45
Copy link
Owner

@mattleibow mattleibow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for the attributes project, look in the host csproj for msbuild props.

… source generator to use MSBuild properties

Co-authored-by: mattleibow <[email protected]>
Copy link
Contributor Author

Copilot AI commented Jun 25, 2025

no need for the attributes project, look in the host csproj for msbuild props.

Removed the attributes project entirely. The source generator now uses MSBuild properties (ApplicationTitle, ApplicationId) instead of attributes. Commit 69bc566.

Copilot AI requested a review from mattleibow June 25, 2025 21:08
Copilot finished work on behalf of mattleibow June 25, 2025 21:08
Copy link
Owner

@mattleibow mattleibow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also make the targets file do the right things. This needs to be a drop-in test suite system.

Copy link
Contributor Author

Copilot AI commented Jun 25, 2025

Please also make the targets file do the right things. This needs to be a drop-in test suite system.

Updated targets file with complete MSBuild integration - adds Info.plist files as PartialAppManifest, processes Windows XAML/manifest files, and excludes Visual Studio test runner files. The source generator now auto-detects MAUI projects with test frameworks for a true drop-in experience. Commit b0d69a2.

Copilot AI requested a review from mattleibow June 25, 2025 21:38
Copilot finished work on behalf of mattleibow June 25, 2025 21:38
Copilot AI requested a review from mattleibow June 26, 2025 10:07
Copilot finished work on behalf of mattleibow June 26, 2025 10:07
</ItemGroup>

<!-- Import the device test app generation targets from Bootstrap package -->
<Import Project="..\..\..\src\DeviceRunners.VisualRunners.Maui.Bootstrap\build\DeviceRunners.VisualRunners.Maui.Bootstrap.props" />
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The props should be right at the top of the file. The first thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the props imports to the top of the project file, right after the Project element. Commit 7155889.

<_ProcessedContent>$(_TemplateContent.Replace('{{RootNamespace}}', '$(RootNamespace)'))</_ProcessedContent>
<_ProcessedContent>$(_ProcessedContent.Replace('{{ApplicationTitle}}', '$(ApplicationTitle)'))</_ProcessedContent>
<_ProcessedContent>$(_ProcessedContent.Replace('{{ApplicationId}}', '$(ApplicationId)'))</_ProcessedContent>
<_ProcessedContent>$(_ProcessedContent.Replace('{{AppId}}', '$(ApplicationId)'))</_ProcessedContent>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace all AppId templating instances with ApplicationId. No need to have of the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced all AppId templating instances with ApplicationId in both the targets file and template files. Commit 7155889.

</PropertyGroup>

<!-- Write processed file -->
<WriteLinesToFile File="%(TemplateFile.Destination)" Lines="$(_ProcessedContent)" Overwrite="true" />
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This task has a WriteOnlyWhenDifferent which we want to be true to reduce build churn

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added WriteOnlyWhenDifferent="true" to the WriteLinesToFile task to reduce build churn. Commit 7155889.

// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace DeviceTestingKitApp.DeviceTests.WinUI;
namespace {{RootNamespace}};
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
namespace {{RootNamespace}};
namespace {{RootNamespace}}.WinUI;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed the namespace template to use {{RootNamespace}}.WinUI as suggested. Commit 7155889.

Copilot AI requested a review from mattleibow June 26, 2025 10:38
Copilot finished work on behalf of mattleibow June 26, 2025 10:38

<!-- Import the device test app generation targets from Bootstrap package -->
<Import Project="..\..\..\src\DeviceRunners.VisualRunners.Maui.Bootstrap\build\DeviceRunners.VisualRunners.Maui.Bootstrap.props" />
<Import Project="..\..\..\src\DeviceRunners.VisualRunners.Maui.Bootstrap\build\DeviceRunners.VisualRunners.Maui.Bootstrap.targets" />
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The props at the top, the targets at the bottom.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed the import ordering - props import moved to top, targets import moved to bottom of the project file. Commit 358c652.

Copilot AI requested a review from mattleibow June 26, 2025 13:26
Copilot finished work on behalf of mattleibow June 26, 2025 13:26
@mattleibow
Copy link
Owner

@copilot Right now, the PR title and description is no longer correct for this PR. Can you give me a new title and description in markdown that I can copy paste directly.

Make sure it encompases all the changes and focuses on the changes. Also note any issues you had and share them.

mattleibow

This comment was marked as off-topic.

Copy link
Contributor Author

Copilot AI commented Jun 26, 2025

@copilot Right now, the PR title and description is no longer correct for this PR. Can you give me a new title and description in markdown that I can copy paste directly.

Make sure it encompases a...

Here's the updated PR title and description:

Title

Create MSBuild template system for automatic DeviceRunners test app bootstrap

Description

This PR introduces a comprehensive MSBuild-based template system that automatically generates all the boilerplate files needed for a DeviceRunners test app, eliminating the need for developers to manually create and maintain platform-specific files.

🔧 Bootstrap Infrastructure

  • DeviceRunners.VisualRunners.Maui.Bootstrap: MSBuild-based template processing system
  • Drop-in NuGet package solution - no attributes or configuration required
  • Auto-detects MAUI projects and generates platform files automatically

🏗️ Generated Files

The bootstrap system automatically creates platform-specific entry points:

  • Android: MainActivity.cs, MainApplication.cs
  • iOS: Program.cs, AppDelegate.cs, Info.plist (via PartialAppManifest)
  • Windows: App.xaml.cs, App.xaml, app.manifest, Package.appxmanifest
  • macOS Catalyst: Program.cs, AppDelegate.cs, Info.plist (via PartialAppManifest)

📝 Simple Usage

Developers can now create a device test app by simply:

  1. Adding a reference to DeviceRunners.VisualRunners.Maui.Bootstrap
  2. Setting standard MSBuild properties:
    <ApplicationTitle>My Test App</ApplicationTitle>
    <ApplicationId>com.company.mytestapp</ApplicationId>

The system automatically detects MAUI projects and generates all necessary files.

⚙️ Configuration

Uses standard MSBuild properties:

  • ApplicationTitle - Application display name
  • ApplicationId - Bundle/package identifier
  • RootNamespace - Code namespace

🧪 Testing & Validation

  • Successfully builds complete test apps across all platforms
  • Integrated with existing DeviceTestingKitApp.DeviceTests sample
  • Template processing with proper namespace replacement

✅ Benefits

  1. Simplified Architecture: Uses MSBuild template processing instead of complex source generators
  2. Zero Configuration: Auto-detects MAUI projects with test frameworks
  3. Drop-in Solution: Just add NuGet package reference
  4. Maintainable: Simple string replacement templates easy to modify
  5. Platform Complete: Handles all MAUI target platforms correctly

🔄 Evolution Notes

This PR initially started as a Roslyn source generator but evolved into a simpler, more maintainable MSBuild template system after realizing that complex code generation wasn't necessary - simple file templating with string replacement achieves the same goal with much less complexity.

💡 Key Technical Decisions

  • MSBuild over Roslyn: Simpler to maintain and debug than source generators
  • Template Files: Stored in NuGet package build/templates/ folder
  • Auto-Detection: No attributes needed - detects MAUI projects automatically
  • Standard Properties: Uses existing MSBuild properties instead of custom attributes
  • Batched Processing: Efficient template processing using MSBuild item batching

This represents a major step toward making device testing as simple as installing a NuGet package.

Addressing #88.

Copilot AI requested a review from mattleibow June 26, 2025 15:02
Copilot finished work on behalf of mattleibow June 26, 2025 15:02
@mattleibow mattleibow changed the title Create Roslyn source generator for automatic DeviceRunners test app generation Create MSBuild template system for automatic DeviceRunners test app bootstrap Jun 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants