Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

controls and forms missing icon and view designer option in vs2019 running SDK project with framework 4.7.2

Summary answer so far: Forms and controls only open in the designer if csproj.user file exists.

The problem story:

I have 2 controls that both inherit from a base control. However one is missing the control icon in the solution explorer missing icon

The good control source starts with

public partial class UniTabMaterialsControl : UnitabBaseControl
{
    public UniTabMaterialsControl()
    {
        InitializeComponent();
    }

The bad control source starts with

public partial class UniTabMaterialsControl : UnitabBaseControl
{
     
    public UniTabMaterialsControl()
    {
        InitializeComponent();
    }

The base control class is

public class UnitabBaseControl : UserControl
{
}

I have tried closing and re-opening Visual Studio

[Update]

I added a new user control and set it to also inherit from UnitabBaseControl , strangely the behaviour corrected.

I was then able to delete the new control and maintain correct behaviour

Git shows that there has been a change in UnitabBaseControl.cs but I do not see what changed other than the colour of the UserControl text

base class colour changed

I then made a fresh clone of the whole solution. This time the incorrect behaviour showed on all the controls that inherited from UnitabBaseControl

[Update]

Now I suffer the same issue with forms

form not showing correct icon

using System.Windows.Forms;

namespace SBD.VivSnap.UI
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
    }
}

and

using System.Windows.Forms;

namespace SBD.VivSnap.UI
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }
    }
}

[Update]

I neglected to mention that my project was a library project referred to by the start up project.

I deleted and then re-added the library project reference in the start up project. Then all the forms and controls appeared correctly.

I could not find any changes in Git to indicate why the solution now worked.

Since then I have noticed the problem in my main project

problem in main project

[Update]

It turns out that my project is in .sdk format even though it is framework 4.7.2 I am thinking this may have something to do with it.

I am using Framework 4.7.2 with an sdk project

Project Sdk="Microsoft.NET.Sdk.WindowsDesktop"

I checked out the code onto a different computer running VS2019 16.1.4 and it builds ok.

I am using 16.11.4

[Update] Now I have updated to 16.11.5 and cloned again but still have the problem.

[Update] The project file is

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
  <PropertyGroup>
    <TargetFramework>net472</TargetFramework>
    <OutputType>WinExe</OutputType>
    <AssemblyName>Main</AssemblyName>
    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
    <RestorePackages>true</RestorePackages>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
    <UseWindowsForms>true</UseWindowsForms>
  </PropertyGroup>
  <PropertyGroup>
    <StartupObject>SBD.VivSnap.Main.Program</StartupObject>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
    <PackageReference Include="Microsoft.Data.SqlClient">
      <Version>2.0.1</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore">
      <Version>3.1.12</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer">
      <Version>3.1.12</Version>
    </PackageReference>
    <PackageReference Include="NuGet.Build.Tasks.Pack" Version="5.7.0">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
    <PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\SnapInUI\SBD.VivSnap.UI.csproj" />
  </ItemGroup>
  <ItemGroup>
    <Compile Update="Properties\Settings.Designer.cs">
      <DesignTimeSharedInput>True</DesignTimeSharedInput>
      <AutoGen>True</AutoGen>
      <DependentUpon>Settings.settings</DependentUpon>
    </Compile>
  </ItemGroup>
  <ItemGroup>
    <None Update="Properties\Settings.settings">
      <Generator>SettingsSingleFileGenerator</Generator>
      <LastGenOutput>Settings.Designer.cs</LastGenOutput>
    </None>
  </ItemGroup>
</Project>

The csproj.user file is in my answer.

like image 664
Kirsten Avatar asked Sep 27 '21 21:09

Kirsten


People also ask

Can't see Windows Form Designer?

We need to enable the designer in Visual Studio. Go to Tools > Options > Environment > Preview Features and select the Use the preview Windows Forms designer for .

How do I access design mode in Visual Studio?

From the Solution Explorer window select your form, right-click, click on View Designer. Voila!

Why doesn't vs 2019 Open the designer for some forms (WinForm)?

I've installed VS 2019 (community) and it fails to open the designer for some Forms (winform). The designer could not be shown for this file because none of the classes within it can be designed. Instances of this error (1) 1.

How to switch to Designer mode in Visual Studio?

You can switch to designer mode pressing "Shift" + "F7". If it doesn't switch, I'll recommend to reinstall VS paying special atention to those packages related to windows forms.

How do I report a problem in Visual Studio 2019?

Please open VS2019 -> Help ->send feedback -> report a problem to report it to VS product team, or access developer community to report it. And if you are inconvenience for it, please feel free to contact me, I would post it through above methods. Then you could comment it with more details.

Why running vs2019 in SafeMode bring multiple issue during the project loading?

Running VS2019 in safemode bring multiple issue during the project loading "The visual studio build manager package package did not load correctly. The problem may be caused by a configuration change or by the installation of another extension. You can get more information ... activitylog.xml"


2 Answers

The form's compile type is probably not set properly as "form" in the .csproj file. Open the .csproj file and make sure you have this line of code wherever "form1.cs" is mentioned:

<Compile Include="form1.cs">
      <SubType>Form</SubType>
    </Compile>
like image 150
user17143414 Avatar answered Nov 11 '22 16:11

user17143414


It turns out that the csproj.user files were not in source control. When I copied myproject.csproj.user to the project folder and opened in VS then the forms appeared correctly.

The file contents is

<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup />
  <ItemGroup>
    <Compile Update="Form1.cs">
      <SubType>Form</SubType>
    </Compile>
    <Compile Update="Form2.cs">
      <SubType>Form</SubType>
    </Compile>
  </ItemGroup>
</Project>

This leaves me with the dilemma of whether or not to check the csproj.user into source control. I had thought this was not necessary before but it seems it is. Plus the name "user" would imply it is user specific.

like image 36
Kirsten Avatar answered Nov 11 '22 15:11

Kirsten