Skip to content

Set <GenerateProgramFile> to false in UnitTest project template to fix CS0017 when building in Visual Studio#6520

Open
lauren-ciha wants to merge 1 commit into
mainfrom
user/laurenciha/cs-unit-test-template-generate-program-file-false
Open

Set <GenerateProgramFile> to false in UnitTest project template to fix CS0017 when building in Visual Studio#6520
lauren-ciha wants to merge 1 commit into
mainfrom
user/laurenciha/cs-unit-test-template-generate-program-file-false

Conversation

@lauren-ciha
Copy link
Copy Markdown
Member

@lauren-ciha lauren-ciha commented May 29, 2026

This is a temporary workaround for CS0017 in the winui-unittest project when built using Visual Studio.

The error is CS0017: Program has more than one entry point defined. Compile with /main to specify the type that contains the entry point.

From my understanding, this error occurs because WinUI apps define their own entry point and if GenerateProgramFiles is true, Microsoft.NET.Test.Sdk.Program.cs is auto-generated with its own entry point.

If the UseWinUI property is not intended to automatically disable the Microsoft.NET.Test.Sdk's auto-generated Microsoft.NET.Test.Sdk.Program.cs with a second entry point, setting GenerateProgramFile to false will do the same thing.

I'm making this PR to unblock other template work. If the targets file changes are made in vstest, I'll remove this later.

Steps to verify:

  • Pull down the branch
  • Run .\dev\Templates\VSIX\build-local-VSIX-package\build-install-localdev-vsix.ps1
  • Open Visual Studio and select "Create a new project"
  • Find the .NET C# WinUI Unit Test template (the one under MVVM, NavigationView, etc.)
  • Create a Unit Test project
  • Build and run using F5

A microsoft employee must use /azp run to validate using the pipelines below.

WARNING:
Comments made by azure-pipelines bot maybe inaccurate.
Please see pipeline link to verify that the build is being ran.

For status checks on the main branch, please use TransportPackage-Foundation-PR
(https://microsoft.visualstudio.com/ProjectReunion/_build?definitionId=81063&_a=summary)
and run the build against your PR branch with the default parameters.

@lauren-ciha lauren-ciha changed the title Set <GenerateProgramFile> to false in UnitTest project template to fix CS0017 when building the template project in VS Set <GenerateProgramFile> to false in UnitTest project template to fix CS0017 and enable the template to build in VS May 29, 2026
@lauren-ciha lauren-ciha changed the title Set <GenerateProgramFile> to false in UnitTest project template to fix CS0017 and enable the template to build in VS Set <GenerateProgramFile> to false in UnitTest project template to fix CS0017 when building in Visual Studio May 29, 2026
@lauren-ciha lauren-ciha marked this pull request as ready for review May 29, 2026 16:34
@lauren-ciha lauren-ciha requested review from DinahK-2SO, Scottj1s and Copilot and removed request for Scottj1s May 29, 2026 16:35
@lauren-ciha lauren-ciha requested a review from guimafelipe May 29, 2026 16:35
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the C# WinUI UnitTest project template to avoid duplicate entry points when generated projects are built in Visual Studio.

Changes:

  • Disables Microsoft.NET.Test.Sdk auto-generation of Program.cs by setting <GenerateProgramFile>false</GenerateProgramFile>.
  • Preserves the WinUI/XAML-generated application entry point used by the self-hosted unit test runner.

<EnableMsixTooling>true</EnableMsixTooling>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GenerateProgramFile>false</GenerateProgramFile>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does this have any side effect on the unit test apps at all?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No. In manual testing, the tests build and run as expected.

@lauren-ciha
Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@lauren-ciha lauren-ciha force-pushed the user/laurenciha/cs-unit-test-template-generate-program-file-false branch from 5787362 to 34567f8 Compare May 29, 2026 21:38
…x CS0017 when building the template project in VS
@lauren-ciha lauren-ciha force-pushed the user/laurenciha/cs-unit-test-template-generate-program-file-false branch from 34567f8 to 4c127e2 Compare June 1, 2026 17:37
@lauren-ciha
Copy link
Copy Markdown
Member Author

The fix for this issue is now in microsoft/vstest's main. Once it is released, I'll validate locally and remove the change in this PR from the unit test project. In the meantime, I plan to merge this PR to unblock building the unit test template.

@lauren-ciha
Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants