Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "http://json.schemastore.org/template",
"author": "Microsoft",
"classifications": ["Common", "WinForms"],
"classifications": [ "Common", "WinForms" ],
"name": "Windows Forms App",
"generatorVersions": "[1.0.0.0-*)",
"description": "A project template for creating a .NET Windows Forms (WinForms) App.",
Expand Down Expand Up @@ -49,10 +49,6 @@
"defaultValue": "net6.0",
"displayName": "Framework"
},
"UseWindowsDesktopSdk": {
"type": "computed",
"value": "(Framework == \"netcoreapp3.1\")"
},
"langVersion": {
"type": "parameter",
"datatype": "text",
Expand All @@ -78,6 +74,23 @@
"defaultValue": "true",
"description": "Whether to enable nullable reference types for this project.",
"displayName": "Enable nullable"
},
"csharp10orLater": {
"type": "generated",
"generator": "regexMatch",
"datatype": "bool",
"parameters": {
"pattern": "^(|10\\.0|10|preview|latest|default|latestMajor)$",
"source": "langVersion"
}
},
"csharpFeature_ImplicitUsings": {
"type": "computed",
"value": "Framework == \"net6.0\" && csharp10orLater == \"true\""
},
"csharpFeature_FileScopedNamespaces": {
"type": "computed",
"value": "(Framework == \"net6.0\" || langVersion != \"\") && csharp10orLater == \"true\""
}
},
"primaryOutputs": [
Expand All @@ -89,24 +102,19 @@
],
"sources": [
{
"exclude": [ "**/[Bb]in/**", "**/[Oo]bj/**", ".template.config/**/*", "**/*.filelist", "**/*.lock.json" ],
"modifiers": [
{
"condition": "(UseWindowsDesktopSdk)",
"exclude": [
"Company.WinFormsApplication1.csproj"
],
"rename": {
"Company.WinFormsApplication3x1.csproj": "Company.WinFormsApplication1.csproj"
}
},
{
"condition": "(!UseWindowsDesktopSdk)",
"exclude": [
"Company.WinFormsApplication3x1.csproj"
]
}
]
"condition": "Framework == \"netcoreapp3.1\"",
"source": "./netcoreapp3.1",
"target": "./"
},
{
"condition": "Framework == \"net5.0\"",
"source": "./net5.0",
"target": "./"
},
{
"condition": "Framework == \"net6.0\"",
"source": "./net6.0",
"target": "./"
}
],
"defaultName": "WinFormsApp1",
Expand All @@ -125,7 +133,7 @@
"id": "open-file",
"condition": "(HostIdentifier != \"dotnetcli\" && HostIdentifier != \"dotnetcli-preview\")",
"description": "Opens Form1.cs in the editor",
"manualInstructions": [ ],
"manualInstructions": [],
"actionId": "84C0DA21-51C8-4541-9940-6CA19AF04EE6",
"args": {
"files": "1"
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework Condition="'$(TargetFrameworkOverride)' == ''">FrameworkParameter-windows</TargetFramework>
<TargetFramework Condition="'$(TargetFrameworkOverride)' != ''">TargetFrameworkOverride-windows</TargetFramework>
<RootNamespace Condition="'$(name)' != '$(name{-VALUE-FORMS-}safe_namespace)'">Company.WinFormsApplication1</RootNamespace>
<LangVersion Condition="'$(langVersion)' != ''">$(ProjectLanguageVersion)</LangVersion>
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we want this to show up in the project file.

Copy link
Member

Choose a reason for hiding this comment

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

Also, has a lower case l

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a command line argument and aligns with this:

"langVersion": {
"type": "parameter",
"datatype": "text",
"description": "Sets langVersion in the created project file",
"defaultValue": "",
"replaces": "$(ProjectLanguageVersion)",
"displayName": "Language Version"
},

The command line args are case sensitive:
image

There's an open tracking issue for this dotnet/templating#3237

<Nullable Condition="'$(Nullable)' == 'true'">enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings Condition="'$(csharpFeature_ImplicitUsings)' == 'true'">enable</ImplicitUsings>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Compile Update="Form1.cs">
<SubType>Form</SubType>
</Compile>
</ItemGroup>
</Project>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#if (!csharpFeature_ImplicitUsings)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

#endif
#if (csharpFeature_FileScopedNamespaces)
namespace Company.WinFormsApplication1;
Copy link
Member

Choose a reason for hiding this comment

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

I thought the decision was not to use these in the templates, and have the VS option apply formatting to decide which form to use?

Copy link
Member

Choose a reason for hiding this comment

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

For templates that aren't splitting their identity based on TFM and accept a language version parameter (like these), yes, I believe that was the decision.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These changes were suggested to us by the dotnet/templating team and aligns with changes made in that repo (e.g. dotnet/templating#3454).

Copy link
Member

Choose a reason for hiding this comment

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

@Pilchie @KathleenDollard was it that item templates would keep using block-scoped namespace declarations, but the project templates that had an option to change the language version would selectively apply file-scoped when the version was high-enough (or not specified) perhaps?


public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
#else
namespace Company.WinFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#if (!csharpFeature_ImplicitUsings)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

#endif
#if (csharpFeature_FileScopedNamespaces)
namespace Company.WinFormsApplication1;

static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
ApplicationConfiguration.Initialize();
Application.Run(new Form1());
}
}
#else
namespace Company.WinFormsApplication1
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
ApplicationConfiguration.Initialize();
Application.Run(new Form1());
}
}
}
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Compile Update="Form1.cs">
<SubType>Form</SubType>
</Compile>
</ItemGroup>
</Project>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Company.WinFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

}
}
Loading