How do you properly integrate a framework/boilerplate NuGet package into your web app in ASP.NET Core?

Viewed 186

I have written a prototype RCL, which contains the following structure:

directory structure

Now I want to implement this logic to override the local files in an another web app, using this directory structure above as a framework, which overrides files.

For that I wrote the following .props file:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   
        
    <Target Name="CopyFiles" BeforeTargets="Build">
        <ItemGroup>
            <File Include="$(MSBuildThisFileDirectory)..\Areas\**\*.*"></File>
            <File Include="$(MSBuildThisFileDirectory)..\Areas\**\**\*.*"></File>
        </ItemGroup>
        
        <Exec Command="xcopy /I/e/d/s/y %(File.Identity) $(ProjectDir)Pages\Shared"></Exec>
            
    </Target>

</Project>

.csproj has this appended:

<ItemGroup>
        <None Include="Areas\**\*.*" Pack="true" PackagePath="Areas"></None>
        <None Include="Areas\**\**\*.*" Pack="true" PackagePath="Areas"></None>
        <None Include="build\libnamehere.props" Pack="true" PackagePath="build"></None>
</ItemGroup>

But this appears to only copy the .cshtml.cs files, which is not good enough...

  • How do I copy the .cshtml files as well?

  • Is there a better method to use the _Layout.cshtml from the RCL?

I am using ASP.NET Core 6 (.NET 6) if that matters.

To summarize, I want to make one of my ASP.NET Core apps as a framework so all assets (Razor pages, JS files, C# logic, controllers etc) should be packed in a framework (which as you can see already did partly in my prototype), which can simply be referenced and it overwrites the new web app's pages in case of a conflict. Also, updates of the framework NuGet package should not break the new web app.

P.S.

I just unzipped my NuGet package and I found no .cshtml files inside of it, only .cshtml.cs files. Why???

Update 1

Due to a request I'm redescribing the problem. I made a regular ASP.NET Core web app, and I want to use 90% of the codebase as a boilerplate/framework for my other new projects, since that code would be the same for every project. To achieve this I created a RCL for the .cshtml pages mainly, but it seems NuGet does not pack .cshtml files. For making it "dynamic" I enhanced the Markup with variables from the appsettings.json. I need as well to have the C# logic (Program.cs, Startup.cs etc) in my new projects so I created a .NET Core library or something similar, but I haven't tried exporting it yet, I would like some guidance on that too, since Microsoft's documentation is lacking on this matter too.

0 Answers
Related