到目前为止的总结答案:如果 csproj.user 文件存在,则表单和控件仅在设计器中打开。
问题故事:
I have 2 controls that both inherit from a base control.
However one is missing the control icon in the solution explorer
![missing icon](https://i.stack.imgur.com/4kpy1.png)
良好的控制源始于
public partial class UniTabMaterialsControl : UnitabBaseControl
{
public UniTabMaterialsControl()
{
InitializeComponent();
}
不良控制源始于
public partial class UniTabMaterialsControl : UnitabBaseControl
{
public UniTabMaterialsControl()
{
InitializeComponent();
}
基本控制类是
public class UnitabBaseControl : UserControl
{
}
我尝试过关闭并重新打开 Visual Studio
[Update]
我添加了一个新的用户控件并将其设置为也继承自 UnitabBaseControl ,奇怪的是行为得到了纠正。
然后我能够删除新控件并保持正确的行为
Git 显示 UnitabBaseControl.cs 发生了变化,但除了 UserControl 文本的颜色之外我没有看到什么变化
然后我对整个解决方案进行了新的克隆。
这次,从 UnitabBaseControl 继承的所有控件都显示了不正确的行为
[Update]
现在我在表格方面遇到了同样的问题
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]
我忘记提到我的项目是启动项目引用的图书馆项目。
我删除并重新添加了启动项目中的库项目引用。然后所有表单和控件都正确显示。
我在 Git 中找不到任何更改来表明该解决方案现在有效的原因。
从那时起我就注意到了我的主要项目中的问题
[Update]
事实证明我的项目是.sdk格式,尽管它是framework 4.7.2
我想这可能与此有关。
我在用带有 sdk 项目的框架 4.7.2 https://stackoverflow.com/questions/62255602/how-do-i-reate-an-sdk-style-project-for-a-net-framework-4-7-2-project-in-using
项目 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 文件在我的答案中。