question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Missing Program.vb in Winforms App targeting 3.1 from Visual Studio

See original GitHub issue

.NET version

7.0.100-preview.4.22252.9

Did it work in .NET Framework?

Yes

Did it work in any of the earlier releases of .NET Core or .NET 5+?

Only with netcoreapp3.1 SDK I believe.

Issue description

When creating a NET Core 3.1 WinForms app in VIsual Studio, an error is encountered:

1>------ Build started: Project: WinFormsApp5, Configuration: Debug Any CPU ------ 1>vbc : error BC30420: ‘Sub Main’ was not found in ‘WinFormsApp5’. 1>Done building project “WinFormsApp5.vbproj” – FAILED. ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

This is happening because the Program.vb is not being laid down by the template due to an incorrect condition in template.json When the same template is created on the command line via the following, the Program.vb is created, so no error results. dotnet new winforms -f netcoreapp3.1 -lang VB

The following configuration is causing the errors: Since the TFM is netcoreapp3.1, UseWindowsDesktopSdkis set to true;

    "UseWindowsDesktopSdk": {
      "type": "computed",
      "value": "(Framework == \"netcoreapp3.1\")"
    },

As a result of this, the ApplicationEvents, and other files are excluded:


            "condition": "(UseWindowsDesktopSdk)",
            "exclude": [
              "Company.WinFormsApplication1.vbproj",
              "Company.WinFormsApplicationSkipAppModel1.vbproj",
              "My Project/**/*",
              "ApplicationEvents.vb"
            ],
            "rename": {
              "Company.WinFormsApplication3x1.vbproj": "Company.WinFormsApplication1.vbproj"
            }
          },

However, the Program.vb is ALSO excluded:

          {
            "condition": "(!skipAppModel)",
            "exclude": [
              "Program.vb",
              "Company.WinFormsApplicationSkipAppModel1.vbproj"
            ],
            "copyOnly": [ "My Project/**/*" ]
          },

This happens because skipAppModel is evaluated as false, but the condition above is a negation, so Program.vb is always excluded (hostIsCli == false) in this case, so this will always be false when run from Visual Studio “skipAppModel”: { “type”: “computed”, “value”: “(hostIsCli && !UseAppFramework)” }

Fix here would be to update the skipAppModel condition to: "(UseWindowsDesktopSdk || (hostIsCli && !UseAppFramework))"

Steps to reproduce

Repro steps:

  1. Create a VisualBasic Winforms project targeting NET Core 3.1 in Visual Studio
  2. Build
  3. Observe the Output Window

Build started… 1>------ Build started: Project: WinFormsApp5, Configuration: Debug Any CPU ------ 1>vbc : error BC30420: ‘Sub Main’ was not found in ‘WinFormsApp5’. 1>Done building project “WinFormsApp5.vbproj” – FAILED. ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
phenningcommented, Jun 8, 2022

@RussKie I think its just Application Framework isn’t supported when targeting 3.1.

That appears to be the intent in both the blog posts and in all the previous updates to template.json. It’s just that there was a slight authoring error in the template.json.

Its pretty apparent there is different expected behavior here since 3.1 uses <Project Sdk="Microsoft.NET.Sdk.WindowsDesktop"> and 5.0+ uses <Project Sdk="Microsoft.NET.Sdk">

0reactions
Nora-Zhou01commented, Jul 6, 2022

Verified on the .NET 7.0 Preview6 test pass build: 7.0.100-preview.6.22352.1, this issue is fixed that the .NET Core 3.1 VB WinForms project which created from VS can be built successfully now. 3 1

Read more comments on GitHub >

github_iconTop Results From Across the Web

Visual Basic WinForms Apps in .NET 5 and Visual Studio ...
In Visual Studio 16.8, the WinForms Designer still has a few features missing. Also, the project system, which manages the Project Dialog, does ......
Read more >
c# - .NET Core not showing in target framework dropdown ...
Open Visual studio installer from start menu ... Then in the Application properties change the Target Framework to .Net 3.1.
Read more >
Cannot use .NET 4.7.2 with Visual Studio 2022
I have installed Visual Studio 2022 on a new PC and I want to create a new project in Visual Basic using .NET...
Read more >
.NET core vs .NET framework
Wondering about the difference between .NET Core & .NET Framework? Here's a quick guide on how to pick the right runtime environment for...
Read more >
Solution to Visual Studio 2022 messing up ...
However I noticed that Visual Studio 2022 RTM install messed up Visual Studio ... App 3.1.9 [C:\Program Files (x86)\dotnet\shared\Microsoft.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found