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
Conversation
Contributor
There was a problem hiding this comment.
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.Sdkauto-generation ofProgram.csby setting<GenerateProgramFile>false</GenerateProgramFile>. - Preserves the WinUI/XAML-generated application entry point used by the self-hosted unit test runner.
guimafelipe
approved these changes
May 29, 2026
| <EnableMsixTooling>true</EnableMsixTooling> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| <GenerateProgramFile>false</GenerateProgramFile> |
Contributor
There was a problem hiding this comment.
Does this have any side effect on the unit test apps at all?
Member
Author
There was a problem hiding this comment.
No. In manual testing, the tests build and run as expected.
Member
Author
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
5787362 to
34567f8
Compare
…x CS0017 when building the template project in VS
34567f8 to
4c127e2
Compare
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. |
Member
Author
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
GenerateProgramFilesis true, Microsoft.NET.Test.Sdk.Program.cs is auto-generated with its own entry point.If the
UseWinUIproperty is not intended to automatically disable the Microsoft.NET.Test.Sdk's auto-generatedMicrosoft.NET.Test.Sdk.Program.cswith a second entry point, settingGenerateProgramFileto 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:
.\dev\Templates\VSIX\build-local-VSIX-package\build-install-localdev-vsix.ps1A 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.