2017-02-09 39 views
1

我试图从Bundle & Minifier(https://marketplace.visualstudio.com/items?itemName=MadsKristensen.BundlerMinifier)获取我所有捆绑文件的列表,但是我无法使用ASP.NET Core 1.1在Build动作中读取标记为“内容”的文件...阅读ASP.NET Core 1.1中的“内容”文件?

enter image description here

我bundleconfig.json的内容是这样的:

[ 
    { 
    "outputFileName": "wwwroot/lib/_bundles/default.js", 
    "inputFiles": [ 
     "wwwroot/lib/jquery/dist/jquery.js", 
     "wwwroot/lib/jsrender/jsrender.js", 
     "wwwroot/lib/jquery/dist/jquery.js", 
     "wwwroot/lib/numeral/src/numeral.js", 
     "wwwroot/lib/numeral/src/locales/da-dk.js",  
    ], 
    "minify": { 
     "enabled": true, 
     "renameLocals": true 
    } 
    }, 
] 

...和构建操作设置为 “内容”。

我的文件进行读取代码...

Assembly _assembly; 
StreamReader _textStreamReader; 
_assembly = Assembly.GetExecutingAssembly(); 
_textStreamReader = new StreamReader(_assembly.GetManifestResourceStream("bundleconfig.json")); 
var j = JObject.Parse(_textStreamReader.ReadToEnd()); 
JArray files = (JArray)j[0]["inputFiles"]; 
List<string> filesList = files.Select(c => (string)c).ToList(); 

但我得到的new StreamReader(_assembly.GetManifestResourceStream("bundleconfig.json"));线空exeption。

任何建议如何阅读此文件?

感谢

+0

GetManifestResourceStream是用于加载编译资源,即成为汇编代码一部分的文件。您是否尝试过使用System.IO的某个部分加载文件,例如文件? –

回答

1

您尝试相同的是: 文件project.json添加设置:

"publishOptions": { 
    "includeFiles": [ "appsettings.json", "bundleconfig.json" ] 
}, 

而且在文件Program.cs的

var bundleconfig = new ConfigurationBuilder() 
        .SetBasePath(Directory.GetCurrentDirectory()) 
        .AddJsonFile("bundleconfig.json", optional: true) 
        .Build(); 
+0

我在Core 1.1中没有看到“project.json”? – MojoDK

+0

另外,如果我尝试你的代码,我得到一个错误.... FormatException:无法解析JSON文件。行号为'1'的错误:'['....我无法在不破坏bundle&minifier的情况下编辑bundleconfig.json。 – MojoDK

+0

也许你创建的项目不完全。我已经创建了项目演示:https://www.screencast.com/t/1DId8lRF –