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# :
<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
}
}
</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:
<code>internal record TasksManagementPageEnglishLocalization : TasksManagementPageLocalization
internal override FilteringModalDialog filteringModalDialog { get; init; } = new()
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.")
};
}
</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:
<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
</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.