繁体   English   中英

使用框架 4.7.2 运行 SDK 项目的 vs2019 中的控件和表单缺少图标和视图设计器选项

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

到目前为止的总结答案:如果 csproj.user 文件存在,表单和控件仅在设计器中打开。

问题故事:

我有 2 个控件,它们都继承自一个基本控件。 但是,解决方案资源管理器中缺少控件图标缺少图标

好的控制源始于

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

坏的控制源开始于

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

基本控件类是

public class UnitabBaseControl : UserControl
{
}

我尝试关闭并重新打开 Visual Studio

[更新]

我添加了一个新的用户控件并将其设置为也继承自 UnitabBaseControl ,奇怪的是行为已得到纠正。

然后我能够删除新控件并保持正确的行为

Git 显示 UnitabBaseControl.cs 发生了变化,但除了 UserControl 文本的颜色之外,我没有看到其他变化

基类颜色已更改

然后我制作了整个解决方案的新克隆。 这次在继承自 UnitabBaseControl 的所有控件上都显示了错误行为

[更新]

现在我在表单上遇到了同样的问题

表单未显示正确的图标

using System.Windows.Forms;

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

using System.Windows.Forms;

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

[更新]

忽略了,我的项目是启动项目所引用的库项目。

我删除然后重新添加启动项目中的库项目引用。 然后所有的窗体和控件都正确显示。

我在 Git 中找不到任何更改来说明为什么该解决方案现在有效。

从那时起我就注意到了我的主要项目中的问题

主项目的问题

[更新]

事实证明,我的项目是 .sdk 格式,即使它是框架 4.7.2 我认为这可能与它有关。

我在sdk 项目中使用Framework 4.7.2

项目 Sdk="Microsoft.NET.Sdk.WindowsDesktop"

我在另一台运行 VS2019 16.1.4 的计算机上检查了代码,它构建正常。

我正在使用 16.11.4

[更新] 现在我已经更新到 16.11.5 并再次克隆,但仍然存在问题。

[更新] 项目文件是

<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>

csproj.user 文件在我的答案中。

表单的编译类型可能没有在 .csproj 文件中正确设置为“表单”。 打开 .csproj 文件并确保在提到“form1.cs”的任何地方都有这行代码:

<Compile Include="form1.cs">
      <SubType>Form</SubType>
    </Compile>

事实证明,csproj.user 文件不在源代码管理中。 当我将 myproject.csproj.user 复制到项目文件夹并在 VS 中打开时,表单显示正确。

文件内容是

<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>

这让我陷入了是否将 csproj.user 签入源代码管理的困境。 我以前认为这没有必要,但似乎确实如此。 加上名称“用户”将暗示它是特定于用户的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM