2017-03-08 236 views
5

我已經有他自己的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包中的新方法。

我如何嵌入我的看法?

回答

10

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

相關問題