I've a nuget package that has his own mvc control pannel, with controllers, views and routes.
This nuget package is imported in other .net core web applications.
At Visual Studio 2015, with .net core, I used the following code to compile the views as resources, allowing them to be found by razor engine and then rendered correctly.
At project.json (nuget):
"buildOptions": {
"embed": "**/Views/**/*.cshtml"
}
At Startup.cs (web application):
public void ConfigureServices(IServiceCollection services)
{
services.Configure<RazorViewEngineOptions>(options =>
{
options.FileProviders.Add(new CompositeFileProvider(
new EmbeddedFileProvider(
typeof(HomeController).GetTypeInfo().Assembly,
"Some.Namespace"))
);
});
return new IuguPortalBuilder(services);
}
In Visual Studio 2017, the project.json file.doesn't exists anymore, and I'm unable to find find a new way to embed my views in the nuget package.
How can I embed my views?
Open Solution Explorer add files you want to embed. Right click on the files then click on Properties . In Properties window and change Build Action to Embedded Resource . After that you should write the embedded resources to file in order to be able to run it.
In Visual Studio, open a SharePoint solution. In Solution Explorer, choose a SharePoint project node, and then, on the menu bar, choose Project > Add New Item. In the Add New Item dialog box, choose the Global Resources File template, and then choose the Add button.
Click in the solution explorer the file that will be modified. Then hit F4 or click with the right button in the file and then select the "Properties" option. In the Properties window, change Build Action to Embedded Resource.
In Solution Explorer
right click on desired file, click Properties
and in opened window set Build action
to Embedded resource
- all like in old days :)
This will create following lines to your *.csproj
file:
<ItemGroup>
<EmbeddedResource Include="Views\Home\Index.cshtml" />
</ItemGroup>
Now MSBuild will add this file as embedded resource into your assembly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With