Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create new Web API using dotnet new webapi with use-minimal-apis and use-program-main options set, you get a warning on build #41491

Closed
1 task done
balachir opened this issue May 3, 2022 · 1 comment · Fixed by #41499
Assignees
Labels
area-web-frameworks *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels feature-templates
Milestone

Comments

@balachir
Copy link

balachir commented May 3, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Create new Web API using dotnet new webapi with use-minimal-apis and use-program-main options set, you get a warning on build.

The entry point of the program is global code; ignoring 'Program.Main(string[])' entry point.

This seems to be happening because it creates both a Program.Main.cs and a Program.cs.

Expected Behavior

No warnings or errors on build

Steps To Reproduce

INSTALL STEPS

  1. Clean Windows 10 x64 machine
  2. Install .NET SDK 6.0.300

REPRO STEPS

  1. Create new Web API using dotnet new with use-minimal-apis and use-program-main options set
  2. Build project dotnet build
>dotnet new webapi -o WebApi02 --use-minimal-apis --use-program-main
The template "ASP.NET Core Web API" was created successfully.

Processing post-creation actions...
Running 'dotnet restore' on C:\Users\<user>\Solutions\Projects02\WebApi02\WebApi02.csproj...
  Determining projects to restore...
  Restored C:\Users\<user>\Solutions\Projects02\WebApi02\WebApi02.csproj (in 352 ms).
Restore succeeded.



>cd WebApi02

>dotnet build
Microsoft (R) Build Engine version 17.2.0+41abc5629 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
  All projects are up-to-date for restore.
C:\Users\<user>\Solutions\Projects02\WebApi02\Program.Main.cs(5,24): warning CS7022: The entry point of the program is
global code; ignoring 'Program.Main(string[])' entry point. [C:\Users\<user>\Solutions\Projects02\WebApi02\WebApi02.csp
roj]
  WebApi02 -> C:\Users\<user>\Solutions\Projects02\WebApi02\bin\Debug\net6.0\WebApi02.dll

Build succeeded.

C:\Users\<user>\Solutions\Projects02\WebApi02\Program.Main.cs(5,24): warning CS7022: The entry point of the program is
global code; ignoring 'Program.Main(string[])' entry point. [C:\Users\<user>\Solutions\Projects02\WebApi02\WebApi02.csp
roj]
    1 Warning(s)
    0 Error(s)

Time Elapsed 00:00:05.16

Exceptions (if any)

No response

.NET Version

6.0.300

Anything else?

I'm also able to reproduce this with SDK 6.0.203.

@javiercn javiercn added the area-web-frameworks *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels label May 3, 2022
@DamianEdwards
Copy link
Member

Taking a look at the source it seems the Web API template isn't intended to support both --use-program-main and --use-minimal-apis simultaneously, but when they are both specified it doesn't correctly remove the top-level statements based .cs file.

At any rate, it seems odd now that those two options shouldn't be supported together (i.e. use a full Program class but use minimal APIs rather than controllers for the web APIs). I'll update the template to support this combination in 7.x and we can backport that fix to the 6.0.xxx servicing trains.

@DamianEdwards DamianEdwards self-assigned this May 3, 2022
@DamianEdwards DamianEdwards added this to the 7.0-preview5 milestone May 3, 2022
DamianEdwards added a commit that referenced this issue May 3, 2022
- Updated test cases to cover more options combinations
- Fixed route pattern typo in minimal APIs case
- Added missing UseAuthorization call in minimal APIs + Windows Auth case
- Fail template tests if a compiler warning is output on build or publish

Fixes #41491
DamianEdwards added a commit that referenced this issue May 5, 2022
- Updated test cases to cover more options combinations
- Fixed route pattern typo in minimal APIs case
- Added missing UseAuthorization call in minimal APIs + Windows Auth case
- Fail template tests if a compiler warning is output on build or publish
- Fix Web API template when call graph option is true
- Add arg constants & fix formatting

Fixes #41491
DamianEdwards added a commit that referenced this issue May 5, 2022
- Updated test cases to cover more options combinations
- Fixed route pattern typo in minimal APIs case
- Added missing UseAuthorization call in minimal APIs + Windows Auth case
- Fail template tests if a compiler warning is output on build or publish
- Fix Web API template when call graph option is true
- Add arg constants & fix formatting

Fixes #41491
DamianEdwards added a commit that referenced this issue May 12, 2022
- Updated test cases to cover more options combinations
- Fixed route pattern typo in minimal APIs case
- Added missing UseAuthorization call in minimal APIs + Windows Auth case
- Fail template tests if a compiler warning is output on build or publish
- Fix Web API template when call graph option is true
- Add arg constants & fix formatting

Fixes #41491
dougbu pushed a commit that referenced this issue May 16, 2022
* Fix templates sourceName
* Support minimal APIs & program/main together in Web API template

  - Updated test cases to cover more options combinations
  - Fixed route pattern typo in minimal APIs case
  - Added missing UseAuthorization call in minimal APIs + Windows Auth case
  - Fail template tests if a compiler warning is output on build or publish
  - Fix Web API template when call graph option is true
  - Add arg constants & fix formatting

Fixes #41491

* Clean-up from template fix port

  - Update template scripts to use correct package version when using locally
  - Update template-baselines.json to cover new template options

* Update for VS compiler changes to nullability & u8 string literals

* Template baselines test fix

* Make template baseline test check namespaces match project name

* Comment for clarity

* Port extra template tests from main

* Port template test change that fails if warnings present on build or publish

* Use original file name in template baseline test

* Fix single file exe test

Now that we fail if "warning" appears in the command output, we have to be sure to now issue and dotnet CLI commands that result in SDK warnings (in this case the change in net6.0 that -r must be accompanied with --self-contained or --no-self-contained).

* Comment out tenmplate baseline test namespace declaration

* Comment out template warning checks

* Apply test fixes from failures investigation

* Set project name

* Bump Helix test runner timeout to 60 mins

* Collect test host dumps on Helix test runner crashes

* Print message when test job times out

Bump helix timeout to match main (45 mins)

* Make helix runner print timestamps with console logs

* Ported more test changes from main

* Revert failing project test if new/build/publish emit restore errors or other warnings.

* Fix typos

* Port TestRunner.cs changes
@ghost ghost locked as resolved and limited conversation to collaborators Jun 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-web-frameworks *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels feature-templates
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants