如何在构建Visual Studio 2017中嵌入资源文件?

问题描述:

我已经有他自己的MVC的控制面板,带有控制器,观点和路由的NuGet包。如何在构建Visual Studio 2017中嵌入资源文件?

这NuGet包在其他.NET核心的Web应用程序导入。

在Visual Studio的2015年,与.NET的核心,我用下面的代码编译意见的资源,使他们能够通过剃刀引擎中找到,然后正确地呈现。

在project.json(的NuGet):

"buildOptions": { 
    "embed": "**/Views/**/*.cshtml" 
    } 

在Startup.cs(Web应用程序):

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); 
} 

在Visual Studio 2017年project.json file.doesn't存在现在,我无法找到一种将我的视图嵌入到nuget包中的新方法。

我如何嵌入我的看法?

Solution Explorer右键单击所需的文件,单击Properties并在打开的窗口中设置Build actionEmbedded resource - 都喜欢在过去:)

这将创建下列行到你的*.csproj文件:

<ItemGroup> 
    <EmbeddedResource Include="Views\Home\Index.cshtml" /> 
</ItemGroup> 

现在MSBuild将把这个文件作为嵌入式资源添加到你的程序集中。

+0

嗨@Dmitry!我可以使用像“Views/*/*。cshtml”这样的通配符来一次导入所有视图吗? –

+0

@Carlos,我不知道,只是尝试和分享:) – Dmitry

+2

刚试过在VS2017:它的工作对我像'包括=“** \翻译\资源* RESX。”'的格式 – Myobis