.Net solution with muliple projects containing blocks and pageTypes

Vote:
 

Hi all,

I'm trying to split up my project into multiple projects for reusage in different solutions.

Solution
ModulesProject
   /Modules/Pages/...
   /Modules/Blocks/...
MyOptimizely
/... some stuff in here

After including the dependencies and building the main optimizely project I can choose the pageTypes and or blocks, but then the views are not found:

InvalidOperationException: The view '/Modules/Pages/Standard/Views/StandardPage.cshtml' was not found. 
The following locations were searched: /Modules/Pages/Standard/Views/StandardPage.cshtml

The same happens, when placing the "image" block on a working page (not StandardPage)

InvalidOperationException: The view 'Components/ImageBlock//Modules/Blocks/Image/Views/index.cshtml' was not found. 
The following locations were searched:/Modules/Blocks/Image/Views/index.cshtml

There the "Components/ImageBlock" is added somehow.

Do I have to create some links inside myOptimizely project. This would destroy my modular solution.

Have a happy new Year

#294061
Jan 03, 2023 15:10
Vote:
 

https://learn.microsoft.com/en-us/aspnet/core/mvc/advanced/app-parts?view=aspnetcore-7.0

You need to add the assembly to the application parrts.

public void ConfigureServices(IServiceCollection services)
{
    var assembly = typeof(MySharedController).Assembly;
    services.AddControllersWithViews()
        .AddApplicationPart(assembly)
        .AddRazorRuntimeCompilation();

    services.Configure<MvcRazorRuntimeCompilationOptions>(options => 
    { options.FileProviders.Add(new EmbeddedFileProvider(assembly)); });
}
#294063
Jan 03, 2023 17:44
Vote:
 

Thank you Mark,

Works like charm. I also had to add

    <ItemGroup>
        <PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="3.1.6" />
        <PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="3.0.0" />
    </ItemGroup>

to the project file main.csproj and the paths to the template-files in the shared.csproj. But thanks to the link I found these dependencies

Have a great 2023

#294115
Jan 04, 2023 8:31
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.