How to import some classes from “.NET MAUI Blazor Hybriod App” project to plain C# project without errors?

My project is the .NET MAUI Blazor Hybriod App

but independently on building/debugging of this application, I need to generate some data by C# :

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>public class GeneratorOfAssetsForStaticPreview
{
public static void Main()
{
GeneratorOfAssetsForStaticPreview.GenerateDummyData();
GeneratorOfAssetsForStaticPreview.GenerateBusinessRules();
GeneratorOfAssetsForStaticPreview.GenerateStaticStrings();
}
private static void GenerateBusinessRules() {
// Generate data and write to file
}
private static void GenerateDummyData() {
// Generate data and write to file
}
private static void GenerateStaticStrings() {
// Generate data and write to file
}
}
</code>
<code>public class GeneratorOfAssetsForStaticPreview { public static void Main() { GeneratorOfAssetsForStaticPreview.GenerateDummyData(); GeneratorOfAssetsForStaticPreview.GenerateBusinessRules(); GeneratorOfAssetsForStaticPreview.GenerateStaticStrings(); } private static void GenerateBusinessRules() { // Generate data and write to file } private static void GenerateDummyData() { // Generate data and write to file } private static void GenerateStaticStrings() { // Generate data and write to file } } </code>
public class GeneratorOfAssetsForStaticPreview
{
  
  public static void Main()
  {
    
    GeneratorOfAssetsForStaticPreview.GenerateDummyData();
    GeneratorOfAssetsForStaticPreview.GenerateBusinessRules();
    GeneratorOfAssetsForStaticPreview.GenerateStaticStrings();

  }
  
 private static void GenerateBusinessRules() {
  // Generate data and write to file
 }
  
 private static void GenerateDummyData() {
  // Generate data and write to file
 }
 
 private static void GenerateStaticStrings() {
  // Generate data and write to file
 }
  
}

This data does not require for the application, but using some classes of the application like these one:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>internal record TasksManagementPageEnglishLocalization : TasksManagementPageLocalization
{
internal override FilteringModalDialog filteringModalDialog { get; init; } = new()
{
title = "Filter Tasks"
};
internal override string taskManagerActivationGuidance { get; } =
"Click or tap the task card to view details or edit the dedicated task.";
internal override SuccessMessages successMessages { get; init; } = new()
{
taskAddingSucceeded = "Task has been added.",
taskUpdatingSucceeded = "Task has been updated",
taskDeletingSucceeded = "Task has been deleted."
};
internal override ErrorMessages errorMessages { get; init; } = new()
{
taskAddingFailed = SharedStaticEnglishStrings.SingleInstance.
buildDataRetrievingOrSubmittingFailedPoliteMessage("The malfunction has occurred during adding of new task."),
taskUpdatingFailed = SharedStaticEnglishStrings.SingleInstance.
buildDataRetrievingOrSubmittingFailedPoliteMessage("The malfunction has occurred during updating of task."),
taskDeletingFailed = SharedStaticEnglishStrings.SingleInstance.
buildDataRetrievingOrSubmittingFailedPoliteMessage("The malfunction has occurred during deleting of task.")
};
}
</code>
<code>internal record TasksManagementPageEnglishLocalization : TasksManagementPageLocalization { internal override FilteringModalDialog filteringModalDialog { get; init; } = new() { title = "Filter Tasks" }; internal override string taskManagerActivationGuidance { get; } = "Click or tap the task card to view details or edit the dedicated task."; internal override SuccessMessages successMessages { get; init; } = new() { taskAddingSucceeded = "Task has been added.", taskUpdatingSucceeded = "Task has been updated", taskDeletingSucceeded = "Task has been deleted." }; internal override ErrorMessages errorMessages { get; init; } = new() { taskAddingFailed = SharedStaticEnglishStrings.SingleInstance. buildDataRetrievingOrSubmittingFailedPoliteMessage("The malfunction has occurred during adding of new task."), taskUpdatingFailed = SharedStaticEnglishStrings.SingleInstance. buildDataRetrievingOrSubmittingFailedPoliteMessage("The malfunction has occurred during updating of task."), taskDeletingFailed = SharedStaticEnglishStrings.SingleInstance. buildDataRetrievingOrSubmittingFailedPoliteMessage("The malfunction has occurred during deleting of task.") }; } </code>
internal record TasksManagementPageEnglishLocalization : TasksManagementPageLocalization
{

  internal override FilteringModalDialog filteringModalDialog { get; init; } = new()
  {
    title = "Filter Tasks"
  };
  
  internal override string taskManagerActivationGuidance { get; } = 
      "Click or tap the task card to view details or edit the dedicated task.";

  internal override SuccessMessages successMessages { get; init; } = new()
  {
    taskAddingSucceeded = "Task has been added.",
    taskUpdatingSucceeded = "Task has been updated",
    taskDeletingSucceeded = "Task has been deleted."
  };
  
  internal override ErrorMessages errorMessages { get; init; } = new()
  {
    taskAddingFailed = SharedStaticEnglishStrings.SingleInstance.
        buildDataRetrievingOrSubmittingFailedPoliteMessage("The malfunction has occurred during adding of new task."),
    taskUpdatingFailed = SharedStaticEnglishStrings.SingleInstance.
        buildDataRetrievingOrSubmittingFailedPoliteMessage("The malfunction has occurred during updating of task."),
    taskDeletingFailed = SharedStaticEnglishStrings.SingleInstance.
      buildDataRetrievingOrSubmittingFailedPoliteMessage("The malfunction has occurred during deleting of task.")
  };

}

All of these classes does not use the .NET MAUI API and Blazor API directly so theoretically could be imported to other projects which does not use the .NET MAUI.

Ideally is to place the GeneratorOfAssetsForStaticPreview class at the same project because this way the pain with imports will be minimal (for example, the above TasksManagementPageEnglishLocalization could be kept internal). All that left is execute the Main method. But AFAIK it is impossible to have more than one entry point in same project and also start the execution from the non-Main methods. If I am wrong, the solution will be simple. If I am right, it is required to move the GeneratorOfAssetsForStaticPreview to another project.

Well, but it is still required to access to some classes of .NET MAUI Blazor Hybriod App. Seems like nothing difficult: unfold the project in the solution explorer, right click on “Depencencies”, “Add project reference”.

But, once it has done, the strange things will begin in previously valid code.

Before:

After (no changes in source code):

The errors are:

  • Cannot resolve symbol 'System'
  • Cannot resolve symbol 'Newtonsoft'
  • Cannot resolve symbol 'Path'
  • Cannot resolve symbol 'void'

It we try to execute the GeneratorOfAssetsForStaticPreview.Main, it will fail with:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Error (active) MSB4018 The "GenerateStaticWebAsssetsPropsFile" task failed unexpectedly.
System.IO.DirectoryNotFoundException: Could not find a part of the path 'D:IntelliJ IDEAMyProjectImplementationElementsClientobjDebugnet8.0-androidstaticwebassetsmsbuild.Client.Microsoft.AspNetCore.StaticWebAssets.props'.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.File.InternalWriteAllBytes(String path, Byte[] bytes, Boolean checkHost)
at Microsoft.AspNetCore.StaticWebAssets.Tasks.GenerateStaticWebAsssetsPropsFile.ExecuteCore()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() Client (net8.0-android) C:Program Filesdotnetsdk8.0.302SdksMicrosoft.NET.Sdk.StaticWebAssetstargetsMicrosoft.NET.Sdk.StaticWebAssets.Pack.targets 136
Error (active) NU1201 Project Client is not compatible with net8.0 (.NETCoreApp,Version=v8.0). Project Client supports:
- net8.0-android34.0 (.NETCoreApp,Version=v8.0)
- net8.0-ios17.2 (.NETCoreApp,Version=v8.0)
- net8.0-maccatalyst17.2 (.NETCoreApp,Version=v8.0)
- net8.0-windows10.0.19041 (.NETCoreApp,Version=v8.0) GeneratorOfAssetsForStaticPreview D:IntelliJ IDEAMyProjectAutomationGeneratorOfAssetsForStaticPreviewGeneratorOfAssetsForStaticPreview.csproj 1
Error (active) Project '....ImplementationElementsClientClient.csproj' targets 'net8.0-maccatalyst;net8.0-ios;net8.0-android;net8.0-windows10.0.19041.0'. It cannot be referenced by a project that targets '.NETCoreApp,Version=v8.0'. GeneratorOfAssetsForStaticPreview C:Program FilesMicrosoft Visual Studio2022CommunityMSBuildCurrentBinamd64Microsoft.Common.CurrentVersion.targets 1879
</code>
<code>Error (active) MSB4018 The "GenerateStaticWebAsssetsPropsFile" task failed unexpectedly. System.IO.DirectoryNotFoundException: Could not find a part of the path 'D:IntelliJ IDEAMyProjectImplementationElementsClientobjDebugnet8.0-androidstaticwebassetsmsbuild.Client.Microsoft.AspNetCore.StaticWebAssets.props'. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) at System.IO.File.InternalWriteAllBytes(String path, Byte[] bytes, Boolean checkHost) at Microsoft.AspNetCore.StaticWebAssets.Tasks.GenerateStaticWebAsssetsPropsFile.ExecuteCore() at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() Client (net8.0-android) C:Program Filesdotnetsdk8.0.302SdksMicrosoft.NET.Sdk.StaticWebAssetstargetsMicrosoft.NET.Sdk.StaticWebAssets.Pack.targets 136 Error (active) NU1201 Project Client is not compatible with net8.0 (.NETCoreApp,Version=v8.0). Project Client supports: - net8.0-android34.0 (.NETCoreApp,Version=v8.0) - net8.0-ios17.2 (.NETCoreApp,Version=v8.0) - net8.0-maccatalyst17.2 (.NETCoreApp,Version=v8.0) - net8.0-windows10.0.19041 (.NETCoreApp,Version=v8.0) GeneratorOfAssetsForStaticPreview D:IntelliJ IDEAMyProjectAutomationGeneratorOfAssetsForStaticPreviewGeneratorOfAssetsForStaticPreview.csproj 1 Error (active) Project '....ImplementationElementsClientClient.csproj' targets 'net8.0-maccatalyst;net8.0-ios;net8.0-android;net8.0-windows10.0.19041.0'. It cannot be referenced by a project that targets '.NETCoreApp,Version=v8.0'. GeneratorOfAssetsForStaticPreview C:Program FilesMicrosoft Visual Studio2022CommunityMSBuildCurrentBinamd64Microsoft.Common.CurrentVersion.targets 1879 </code>
Error (active)  MSB4018 The "GenerateStaticWebAsssetsPropsFile" task failed unexpectedly.
System.IO.DirectoryNotFoundException: Could not find a part of the path 'D:IntelliJ IDEAMyProjectImplementationElementsClientobjDebugnet8.0-androidstaticwebassetsmsbuild.Client.Microsoft.AspNetCore.StaticWebAssets.props'.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.File.InternalWriteAllBytes(String path, Byte[] bytes, Boolean checkHost)
   at Microsoft.AspNetCore.StaticWebAssets.Tasks.GenerateStaticWebAsssetsPropsFile.ExecuteCore()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() Client (net8.0-android) C:Program Filesdotnetsdk8.0.302SdksMicrosoft.NET.Sdk.StaticWebAssetstargetsMicrosoft.NET.Sdk.StaticWebAssets.Pack.targets   136     

Error (active)  NU1201  Project Client is not compatible with net8.0 (.NETCoreApp,Version=v8.0). Project Client supports:
  - net8.0-android34.0 (.NETCoreApp,Version=v8.0)
  - net8.0-ios17.2 (.NETCoreApp,Version=v8.0)
  - net8.0-maccatalyst17.2 (.NETCoreApp,Version=v8.0)
  - net8.0-windows10.0.19041 (.NETCoreApp,Version=v8.0) GeneratorOfAssetsForStaticPreview   D:IntelliJ IDEAMyProjectAutomationGeneratorOfAssetsForStaticPreviewGeneratorOfAssetsForStaticPreview.csproj    1       


Error (active)      Project '....ImplementationElementsClientClient.csproj' targets 'net8.0-maccatalyst;net8.0-ios;net8.0-android;net8.0-windows10.0.19041.0'. It cannot be referenced by a project that targets '.NETCoreApp,Version=v8.0'.   GeneratorOfAssetsForStaticPreview   C:Program FilesMicrosoft Visual Studio2022CommunityMSBuildCurrentBinamd64Microsoft.Common.CurrentVersion.targets   1879        

I suppose, there could be the multiple solutions (XY problem), but please note that I will not extract the classes like TasksManagementPageEnglishLocalization to separate project, because such classes are logically related with Blazor components and must be stored near with these compononets.
Although extracting of these classes to another project is possible, it will be the major impact in the project organizing thus to maintainability.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật