project-system: Add Windows Form does not nest .designer.cs under .cs
I was not able to tell if this issue was already tracked.
Start with this .csproj (15.0.26014.0):
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net452</TargetFramework>
<RuntimeIdentifier>win</RuntimeIdentifier>
</PropertyGroup>
<ItemGroup>
<Compile Include="**\*.cs" />
<EmbeddedResource Include="**\*.resx" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.Windows.Forms" />
</ItemGroup>
</Project>
Select Windows Form in Add New Item and see Form1.cs and Form1.designer.cs nodes are siblings in Solution Explorer, and this is the .csproj:
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net452</TargetFramework>
<RuntimeIdentifier>win</RuntimeIdentifier>
</PropertyGroup>
<ItemGroup>
<Compile Include="**\*.cs" />
<EmbeddedResource Include="**\*.resx" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.Windows.Forms" />
</ItemGroup>
<ItemGroup>
<Compile Update="Form1.cs">
<SubType>Form</SubType>
</Compile>
<Compile Update="Form1.Designer.cs">
<SubType>Form</SubType>
</Compile>
</ItemGroup>
</Project>
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 28 (5 by maintainers)
This is also bugging me.
I’m trying to move entirely into new csproj land, and while most of my stuff will work as is, I have one(!) WinForms app that is holding me back.
Is there anyway, even if undocumented, to make new csproj deal with WinForms projects (while keeping the designer functional)?
I was able to confirm that a call to
LicenseManager.Validate
in a custom control constructor causes the NotImplementedException.That brings this issue to a total of seven issues. Should I start issues for these or are they closely related enough for your purposes?
For me, when I add new form “test.cs” the csproj will contain:
in order to nest the designer, manually edit the csproj by adding right below it, two new nodes in the same ItemGroup:
now, Shift+F7 works, designer works. And I did not include MSBuildSdkExtras
I hate to complain because of the amazing results you’ve already had, but six lines feels a bit more verbose than it needs to be. Is something like this possible? (Is
SubType
needed in the .csproj itself or can that info be cached after examining the contents? Could the nesting be automatic as well?)@jnm2 We’re bringing up WinForms now - let’s use new issues to track each individual issue; bugs we’re aware of are being tracked by the WinForms label: https://github.com/dotnet/project-system/labels/Feature-WinForms.
The nesting itself is being tracked by https://github.com/dotnet/project-system/issues/159, and we’ve implemented for 16.0 using rules of legacy but without DependentUpon. We’ll respect DependentUpon if its present, otherwise, we’ll just auto-nest based on existing rules. I’m going to dupe this bug against it.
@jnm2 @onovotny @johmarjac
I have successfully created the worst msbuild hack of all time…
I basically have two projects for a
X
winforms project OneX.Designer
project which I just use for opening up the designer and editing the crap out of my soon to be dead winforms god willing (If MS support this horrid crap in the future)The Other,
X
, basically uses msbuild goo to “import” every piece of code/structure from the other project automatically, and that’s the one I actually use to build the final executable with dotnet cli toolsI’m attaching the
X.Designer.csproj
,X.csproj
, here and theResurrect-WinForms.targets
file it imports:X.Designer
(the only important thing here is that it builds into thekillme
folder which we need to know in advance about so we can exclude it insideResurrect-WinForms.targets
) :X.csproj
:And here’s
Resurrect-WinForms.targets
:I take no responsibility for anything with this horrid hack I’ve copy pasted above. May the good lord have mercy on your soul.
@onovotny For me it does not even nest Form1.cs and Form1.Designer.cs together allthough I installed (and restored) the MSBuild.Sdk.Extras Package. Here my .csproj
And that’s how it looks in Solution Explorer