找回密码
 立即注册

QQ登录

只需一步,快速开始

Richard.Ma 讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2020-12-2 14:24  /   查看:2256  /  回复:0
本帖最后由 Richard.Ma 于 2020-12-2 14:56 编辑

此博客将介绍如何使用新控件在 .NET 5 WinForms和.NET Core WinForms中创建新项目, 以及如何移植旧项目到新平台中。
用于.NET Core 3.1和 .NET 5 的Spread.NET 14 Windows Forms NuGet包
Spread.NET 14包括了 .NET Core 3.1.NET 5 Winforms的新控件,目前可以在 NuGet 中下载使用用。 当然,控件仍然支持 .NET 4.5.2 目标框架,您可以在所有受支持的平台中使用这些新控件。Spread.NET 14还包括新的使用相同API的全框架控件,因此您可以使用具有完整设计时支持的全框架控件创建新项目,还可以为.NET Core 3.1.NET 5创建平行项目,使用相同的源码针对新控件进行构建,前提是代码可以移植。您可以使用 微软的可移植性分析器工具确定代码到新平台的可移植性。
请注意,在.NET Core 3.1.NET 5 Windows Forms中,新Spread.NET 14控件不像全框架的Spread.NET 14 Windows Forms控件那样在Visual Studio中支持设计时,因此,当您想在Visual Studio中使用Spread.NET 14的完整设计时功能集时,建议使用全框架控件进行开发,例如使用Spread Designer工具设计电子表格。您可以在解决方案中为.NET Core 3.1或.NET 5创建平行项目,并为这些目标框架构建相同的源码。

将项目移植到.NETCore 3.1.NET 5
下面会使用一个示例项目“年度财务报告”,来演示如何将现有的Spread.NET 13 Windows Forms(或更早的版本)项目,通过新的 Spread.NET 14 Windows Forms NuGet 包控件来转换目标框架为.NET Core 3.1或.NET 5

image.png51179503.png

此演示样本随C#和VB.NET的产品一起安装。你可以在安装目录下如下位置找到此演示的C#版本“Samples\C#\Spread.Examples\GrapeCity.AnnualFinancialReport\GrapeCity.AnnualFinancialReport.sln
然后使用Visual Studio Enterprise2019 Preview(Version 16.8.0 Preview4.0)打开

image.png708782653.png
包含多个项目和项目依赖项的解决方案(如本示例)应自下而上处理,首先是没有依赖项的依赖项目,然后是依赖于这些项目的项目。为了避免与binobj文件夹潜在冲突,应在包含相关的.NET全框架项目的文件夹下的子文件夹中创建新的netcore3.1项目。
第 1 步:为新的 netcore3.1 项目创建文件夹
创建以下新文件夹(使用 Windows 资源管理器):

  • Samples\C#\Common\Spread.Commom.DataStore\netcore
  • Samples\C#\Common\Spread.Common.Features\netcore
  • Samples\C#\Spread.Examples\GrapeCity.AnnualFinancialReport\netcore
这些新文件夹将是我们接下来创建的新netcore3.1项目文件的保存位置。
第 2 步:创建项目Spread.Common.DataStore.Core
对于此步骤,转到文件夹 Samples \ C\Common \ Spread.Commom.DataStore并打开正在记事本(或其他文本编辑器)中移植的Spread.Common.DataStore.csproj。这对于将复制到下一步将创建的新项目文件中很有用。
  
使用记事本或其他文本编辑器,创建一个新文件,并将此基线内容粘贴到新的Spread.Common.DataStore.Core项目中:
  
<Project  Sdk="Microsoft.NET.Sdk">
  
  <PropertyGroup>
  
    <TargetFrameworks>netcoreapp3.1;net5.0-windows</TargetFrameworks>
  
    <UseWindowsForms>true</UseWindowsForms>
  
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
  
    <AssemblyName>Spread.Common.DataStore.Core</AssemblyName>
  
    <RootNamespace>Spread.Common.DataStore</RootNamespace>   
  
  </PropertyGroup>
  
  
</Project>
  
  
  
接下来,我们需要添加原始项目中包含的所有文件和资源。在Spread.Common.DataStore.csproj中找到包含源文件和资源文件的块(<ItemGroup>包含<Compile Include = ...><Content Include = ...>),然后将其复制到新项目中,对于粘贴的每个源路径,请在路径前面插入“ .. \”,以修复新项目文件相对于源文件的位置的文件路径:
<ProjectSdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFrameworks>netcoreapp3.1;net5.0-windows</TargetFrameworks>
    <UseWindowsForms>true</UseWindowsForms>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
    <AssemblyName>Spread.Common.DataStore.Core</AssemblyName>
    <RootNamespace>Spread.Common.DataStore</RootNamespace>   
  </PropertyGroup>
  <ItemGroup>
    <CompileInclude="..\DataSourceEntities\COGSDataSource.cs" />
    <CompileInclude="..\DataSourceEntities\DashBoardDataSource.cs" />
    <CompileInclude="..\DataService.cs" />
    <CompileInclude="..\DataSourceEntities\FinancialKPIDataSource.cs" />
    <CompileInclude="..\DataSourceEntities\IncomeStatementDataSource.cs" />
    <CompileInclude="..\DataSourceEntities\JsonDataSource.cs" />
    <CompileInclude="..\DataSourceEntities\KPIDataSource.cs" />
    <CompileInclude="..\DataSourceEntities\AccessDataSource.cs" />
    <CompileInclude="..\DataSourceEntities\OrderEntryDataSource.cs" />
    <CompileInclude="..\DataSourceEntities\StudentCalendarDataSource.cs" />
    <CompileInclude="..\DataSourceEntities\StudentDashboardDataSource.cs" />
    <CompileInclude="..\GCVersion35.cs" />
    <CompileInclude="..\Model\AbsenceSchedule.cs" />
    <CompileInclude="..\Model\AbsentRecord.cs" />
    <CompileInclude="..\Model\BusinessExpense.cs" />
    <CompileInclude="..\Model\BusinessRevenue.cs" />
    <CompileInclude="..\Model\BusinessStat.cs" />
    <CompileInclude="..\Model\COGS.cs" />
    <CompileInclude="..\Model\Company.cs" />
    <CompileInclude="..\Model\Customer.cs" />
    <CompileInclude="..\Model\CustomerTarget.cs" />
    <CompileInclude="..\Model\DashBoardItems.cs" />
    <CompileInclude="..\Model\Employee.cs" />
    <CompileInclude="..\Model\FinancialKPI.cs" />
    <CompileInclude="..\Model\Interfaces\IStudentRecord.cs" />
    <CompileInclude="..\Model\Interfaces\IDateTime.cs" />
    <CompileInclude="..\Model\Invoice.cs" />
    <CompileInclude="..\Model\InvoiceParts.cs" />
    <CompileInclude="..\Model\InvoiceServices.cs" />
    <CompileInclude="..\Model\KPIList.cs" />
    <CompileInclude="..\Model\LastSomeMatchStatus.cs" />
    <CompileInclude="..\Model\MarketSale.cs" />
    <CompileInclude="..\Model\Match.cs" />
    <CompileInclude="..\Model\MatchPointTable.cs" />
    <CompileInclude="..\Model\MovieRecord.cs" />
    <CompileInclude="..\Model\Parts.cs" />
    <CompileInclude="..\Model\Product.cs" />
    <CompileInclude="..\Model\Region.cs" />
    <CompileInclude="..\Model\Sale.cs" />
    <CompileInclude="..\Model\ScoreRecord.cs" />
    <CompileInclude="..\Model\Student.cs" />
    <CompileInclude="..\Model\StudentSchedule.cs" />
    <CompileInclude="..\Model\TardyRecord.cs" />
    <CompileInclude="..\Model\Team.cs" />
    <CompileInclude="..\Model\TermSession.cs" />
    <CompileInclude="..\Model\Vehicle.cs" />
    <CompileInclude="..\Properties\AssemblyInfo.cs" />
    <CompileInclude="..\Utilities\FileUtilities.cs" />
  </ItemGroup>
  <ItemGroup>
    <ContentInclude="..\Data\AbsenceSchedule.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\AbsentRecords.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\AgingReportCustomers.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\AgingReportInvoices.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\BusinessStats.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\Companies.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\Customers.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\CustomerTarget.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\DashBoardCustomers.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\DashBoardInvoices.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\DashBoardTargetMaster.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\Employee.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\movie_data.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\FinancialKPIList.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\FinancialTargetMaster.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\Invoice.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\InvoiceParts.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\InvoiceServices.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\KPIList.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\MarketSales.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <Content Include="..\Data\MatchCurrentYear.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\MatchFourthLastYear.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\MatchLastYear.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\MatchSecondLastYear.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\MatchThirdLastYear.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\Parts.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\Products.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\Regions.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\Sales.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\ScoreRecords.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\Students.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\TardyRecords.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\TargetMaster.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\Team.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\TermSessions.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\Vehicle.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Resources\GrapeCity.thmx">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
  </ItemGroup>
  <ItemGroup>
    <ContentInclude="..\Data\fpnorthwinds.mdb">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\fpWine.mdb">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\Nwind.mdb">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <Content Include="..\Data\Patients2000.mdb">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\receivables.mdb">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
  </ItemGroup>

</Project>
步骤3:添加表单资源
之前的csprojvbproj项目类型会自动包含表单的资源文件,因此,如果您的项目包含任何表单,则还需要在<Project> </ Project>中为每种表单添加资源:
表单资源示例
  
<EmbeddedResource  Include="..\Form.resx">
  
  <DependentUpon>Form.cs</DependentUpon>
  
</EmbeddedResource>
  
在项目文件夹中搜索在新项目中未显式引用的resx文件,并为相关表单添加每个resxcs,如上所示。在此示例中,没有任何形式的resx可以添加到任何项目中,但是您的项目可能包含此类resx文件,如果不包含这些文件,则在执行步骤9并尝试运行以下命令时可能会出错。在这种情况下,通常可以通过在适当的项目中添加缺少的资源来解决问题。
将文件另存为 Samples\C#\Common\Spread.Commom.DataStore\netcore\Spread.Common.DataStore.Core.csproj
注意:
您还必须保存使用Spread.NET WinForms早期版本(v13和更早版本)使用的设计时更改,并使用v14更新一些用于序列化控件的类,因为某些以前在.NET Framework早期版本中可序列化的类在.NET 5中不再可序列化。对于使用较早版本保存的所有Spread XML文件,此过程也是必需的。请注意,XML文件格式已被弃用,建议您将XLSX格式与 Exchangeable标志一起使用。
步骤4:创建项目Spread.Common.Features.Core
重复步骤2-3,来创建新项目Spread.Common.Features.Core
使用Samples\C#\Common\Spread.Commom.Features\Spread.Common.Features.csproj复制源代码和此模板以创建初始的空项目文件:
项目文件:
<ProjectSdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFrameworks>netcoreapp3.1;net5.0-windows</TargetFrameworks>
    <UseWindowsForms>true</UseWindowsForms>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
    <AssemblyName>Spread.Common.Features.Core</AssemblyName>
    <RootNamespace>Spread.Common.Features</RootNamespace>   
  </PropertyGroup>

</Project>

接下来,从 Samples\C#\Common\Spread.Commom.Features\Spread.Common.Features.csproj:复制源码和资源文件(<ItemGroup> 包含<Compile Include=...><Content Include=...>):
<ProjectSdk="Microsoft.NET.Sdk.WindowsDesktop">
  <PropertyGroup>
    <TargetFrameworks>netcoreapp3.1;net5.0-windows</TargetFrameworks>
    <UseWindowsForms>true</UseWindowsForms>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
    <AssemblyName>Spread.Common.Features.Core</AssemblyName>
    <RootNamespace>Spread.Common.Features</RootNamespace>   
  </PropertyGroup>
  <ItemGroup>
    <CompileInclude="..\DataSourceEntities\COGSDataSource.cs" />
    <CompileInclude="..\DataSourceEntities\DashBoardDataSource.cs" />
    <CompileInclude="..\DataService.cs" />
    <CompileInclude="..\DataSourceEntities\FinancialKPIDataSource.cs" />
    <CompileInclude="..\DataSourceEntities\IncomeStatementDataSource.cs" />
    <CompileInclude="..\DataSourceEntities\JsonDataSource.cs" />
    <CompileInclude="..\DataSourceEntities\KPIDataSource.cs" />
    <CompileInclude="..\DataSourceEntities\AccessDataSource.cs" />
    <CompileInclude="..\DataSourceEntities\OrderEntryDataSource.cs" />
    <CompileInclude="..\DataSourceEntities\StudentCalendarDataSource.cs" />
    <CompileInclude="..\DataSourceEntities\StudentDashboardDataSource.cs" />
    <CompileInclude="..\GCVersion35.cs" />
    <CompileInclude="..\Model\AbsenceSchedule.cs" />
    <CompileInclude="..\Model\AbsentRecord.cs" />
    <CompileInclude="..\Model\BusinessExpense.cs" />
    <CompileInclude="..\Model\BusinessRevenue.cs" />
    <CompileInclude="..\Model\BusinessStat.cs" />
    <CompileInclude="..\Model\COGS.cs" />
    <CompileInclude="..\Model\Company.cs" />
    <CompileInclude="..\Model\Customer.cs" />
    <CompileInclude="..\Model\CustomerTarget.cs" />
    <CompileInclude="..\Model\DashBoardItems.cs" />
    <CompileInclude="..\Model\Employee.cs" />
    <CompileInclude="..\Model\FinancialKPI.cs" />
    <CompileInclude="..\Model\Interfaces\IStudentRecord.cs" />
    <CompileInclude="..\Model\Interfaces\IDateTime.cs" />
    <CompileInclude="..\Model\Invoice.cs" />
    <CompileInclude="..\Model\InvoiceParts.cs" />
    <CompileInclude="..\Model\InvoiceServices.cs" />
    <CompileInclude="..\Model\KPIList.cs" />
    <CompileInclude="..\Model\LastSomeMatchStatus.cs" />
    <CompileInclude="..\Model\MarketSale.cs" />
    <CompileInclude="..\Model\Match.cs" />
    <CompileInclude="..\Model\MatchPointTable.cs" />
    <CompileInclude="..\Model\MovieRecord.cs" />
    <CompileInclude="..\Model\Parts.cs" />
    <CompileInclude="..\Model\Product.cs" />
    <CompileInclude="..\Model\Region.cs" />
    <CompileInclude="..\Model\Sale.cs" />
    <CompileInclude="..\Model\ScoreRecord.cs" />
    <CompileInclude="..\Model\Student.cs" />
    <CompileInclude="..\Model\StudentSchedule.cs" />
    <CompileInclude="..\Model\TardyRecord.cs" />
    <CompileInclude="..\Model\Team.cs" />
    <CompileInclude="..\Model\TermSession.cs" />
    <CompileInclude="..\Model\Vehicle.cs" />
    <CompileInclude="..\Properties\AssemblyInfo.cs" />
    <CompileInclude="..\Utilities\FileUtilities.cs" />
  </ItemGroup>
  <ItemGroup>
    <ContentInclude="..\Data\AbsenceSchedule.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\AbsentRecords.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\AgingReportCustomers.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\AgingReportInvoices.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\BusinessStats.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\Companies.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\Customers.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\CustomerTarget.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\DashBoardCustomers.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\DashBoardInvoices.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\DashBoardTargetMaster.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\Employee.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\movie_data.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\FinancialKPIList.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\FinancialTargetMaster.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\Invoice.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\InvoiceParts.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\InvoiceServices.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\KPIList.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\MarketSales.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\MatchCurrentYear.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\MatchFourthLastYear.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\MatchLastYear.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\MatchSecondLastYear.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\MatchThirdLastYear.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\Parts.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\Products.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\Regions.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\Sales.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\ScoreRecords.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\Students.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\TardyRecords.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\TargetMaster.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\Team.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\TermSessions.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\Vehicle.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Resources\GrapeCity.thmx">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
  </ItemGroup>
  <ItemGroup>
    <ContentInclude="..\Data\fpnorthwinds.mdb">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\fpWine.mdb">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\Nwind.mdb">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\Patients2000.mdb">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <ContentInclude="..\Data\receivables.mdb">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
  </ItemGroup>

</Project>


将文件另存为 Samples\C#\Common\Spread.Commom.Features\netcore\Spread.Common.Features.Core.csproj.
步骤5:创建项目GrapeCity.AnnualFinancialReport.Core
重复步骤2-3以创建新项目GrapeCity.AnnualFinancialReport.Core
使用Samples\C#\Examples\GrapeCity.AnnualFinancialReport\GrapeCity.AnnualFinancialReport.csproj复制源码和此模板以创建初始的空项目文件:
GrapeCity.AnnualFinancialReport.Core.csproj
  
<Project  Sdk="Microsoft.NET.Sdk">
  
  <PropertyGroup>
  
    <OutputType>WinExe</OutputType>
  
    <TargetFrameworks>netcoreapp3.1;net5.0-windows</TargetFrameworks>
  
    <UseWindowsForms>true</UseWindowsForms>
  
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
  
    <AssemblyName>GrapeCity.AnnualFinancialReport.Core</AssemblyName>
  
    <RootNamespace>GrapeCity.AnnualFinancialReport</RootNamespace>   
  
  </PropertyGroup>
  
  
</Project>
  
接下来,从 Samples \ C\ Examples \ GrapeCity.AnnualFinancialReport \ GrapeCity.AnnualFinancialReport .csproj复制源和资源文件(<ItemGroup>包含<Compile Include =...><Content Include = ...>):
<ProjectSdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFrameworks>netcoreapp3.1;net5.0-windows</TargetFrameworks>
    <UseWindowsForms>true</UseWindowsForms>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
    <AssemblyName>GrapeCity.AnnualFinancialReport.Core</AssemblyName>
    <RootNamespace>GrapeCity.AnnualFinancialReport</RootNamespace>   
  </PropertyGroup>
  <ItemGroup>
    <CompileInclude="..\AnnualFinancialReport.cs">
      <SubType>UserControl</SubType>
    </Compile>
    <CompileInclude="..\AnnualFinancialReport.Designer.cs">
      <DependentUpon>AnnualFinancialReport.cs</DependentUpon>
    </Compile>
    <CompileInclude="..\Form1.cs">
      <SubType>Form</SubType>
    </Compile>
    <CompileInclude="..\Form1.Designer.cs">
      <DependentUpon>Form1.cs</DependentUpon>
    </Compile>
    <CompileInclude="..\Program.cs" />
    <CompileInclude="..\Properties\AssemblyInfo.cs" />
    <EmbeddedResourceInclude="..\AnnualFinancialReport.resx">
      <DependentUpon>AnnualFinancialReport.cs</DependentUpon>
    </EmbeddedResource>
    <EmbeddedResourceInclude="..\Properties\licenses.licx" />
    <EmbeddedResourceInclude="..\Properties\Resources.resx">
      <Generator>ResXFileCodeGenerator</Generator>
      <LastGenOutput>Resources.Designer.cs</LastGenOutput>
      <SubType>Designer</SubType>
    </EmbeddedResource>
    <CompileInclude="..\Properties\Resources.Designer.cs">
      <AutoGen>True</AutoGen>
      <DependentUpon>Resources.resx</DependentUpon>
      <DesignTime>True</DesignTime>
    </Compile>
    <NoneInclude="..\Properties\app.manifest" />
    <NoneInclude="..\Properties\Settings.settings">
      <Generator>SettingsSingleFileGenerator</Generator>
      <LastGenOutput>Settings.Designer.cs</LastGenOutput>
    </None>
    <CompileInclude="..\Properties\Settings.Designer.cs">
      <AutoGen>True</AutoGen>
      <DependentUpon>Settings.settings</DependentUpon>
      <DesignTimeSharedInput>True</DesignTimeSharedInput>
    </Compile>
    <NoneInclude="..\Resources\AnnualFinancialReport.xlsx" />
    <NoneInclude="..\Resources\ExcelCompatibility.imp" />
  </ItemGroup>

</Project>

将文件另存为Samples\C#\Examples\GrapeCity.AnnualFinancialReport\netcore\GrapeCity.AnnualFinancialReport.Core.csproj.
步骤6:在GrapeCity.AnnualFinancialReport.sln中添加新项目
在名为netcore的解决方案中创建一个新文件夹,然后将每个新项目添加到该文件夹&#8203;&#8203;下的解决方案中:

image.png284117125.png
步骤7:添加新的项目引用
项目Spread.Common.DataStore.Core需要一些包引用。要添加这些引用,请在解决方案资源管理器中展开该项目,然后右键单击“ Dependencies”节点,然后选择“ ManagerNuGet Packages ...”以打开NuGet Package Manager,然后选中“ Include Prerelease”框并使用“浏览选项卡进行搜索Newton.JsonSystem.Data.OleDb软件包,然后从nuget.org安装每个软件包的最新版本–之后,“已安装选项卡应如下所示:

image.png177557982.png
项目GrapeCity.AnnualFinancialReport.Core需要其他两个项目Spread.Common.DataStore.CoreSpread.Common.Features.Core,因此首先使用“添加项目引用...”来添加对这些项目的引用:

image.png812985229.png
然后使用NuGet软件包管理器添加GrapeCity.Spread.WinForms的引用:

image.png143689879.png

步骤8:组织项目文件夹并镜像原始项目结构
最后一步涉及组织新项目中的所有项目源和资源文件链接,以匹配原始项目中的组织和结构,包括所有项目文件夹和子文件夹。
GrapeCity.Common.DataStore项目有很多的子文件夹组织源和资源文件(属性数据DataSourceEntities型号必须在新的内部创建等)GrapeCity.Common.DataStore.Core项目,每个文件的链接必须是移动到适当的文件夹以匹配原始项目的组织。您可以右键单击该项目,然后使用添加→新建文件夹创建文件夹,然后将源文件和资源文件链接拖放到适当的位置。结果应如下所示:

image.png173267821.png

GrapeCity.Common.Features项目也有很多的子文件夹,需要类似的组织。按照上面做的步骤GrapeCity.Common.Features.Core镜的结构GrapeCity.Common.Features,结果应该是这样的:

image.png58279417.png
GrapeCity.AnnualFinancialReport项目只有2子文件夹,属性资源,所以它更容易组织。结果应如下所示:

image.png338076476.png
步骤9:编译并执行
现在,新的netcoreapp3.1项目应该已准备好构建和运行。右键单击GrapeCity.AnnualFinancialReport.Core项目,然后选择Set as Startup Project,然后按F5键开始调试,该项目应该可以正常运行:

10  GrapeCity.AnnualFinancialReport.Core运行
如果确实出现错误,则可能是某些缺少与表单相关联的resx文件,而该文件没有包含在需要在步骤3添加的新csprojvbproj中。
VB项目移植到.NET Core 3.1.NET 5
移植VB项目的工作原理完全相同,除了使用文件类型csproj而不是vbproj,有时还使用不同的文件夹名称(例如,使用My Project而不是Properties),但是适用相同的步骤。
下面链接的示例项目同时包含CVB版本以供参考。
使用设计时界面
新平台控件尚不能很好地支持设计时界面,因此在设计时应继续使用完整框架版本和完整框架项目。在Spread设计性能与e窗口中的所有内置式转换器和编辑器类型可使用较老的设计时开发csprojvbproj项目类型,并且所有更改会自动应用到.NET 5.NET Core 3.1为这些项目构建。

如下是本教程所用的示例项目,大家可以下载后测试编译
GrapeCity.AnnualFinancialReport.Core.CS.zip (2.56 MB, 下载次数: 146)

0 个回复

您需要登录后才可以回帖 登录 | 立即注册
返回顶部