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:
- Create a VisualBasic Winforms project targeting NET Core 3.1 in Visual Studio
- Build
- 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:
- Created a year ago
- Comments:6 (6 by maintainers)
Top GitHub Comments
@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">
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.