Assembly.GetManifestResourceStream为null

 

 

 

想把某个项目的某个文件夹里面的ini文件生成的时候顺便生成为网站和服务文件夹项目

 

string _path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "BorrowFormulaConfig.ini");

if (!File.Exists(_path))
{
FileStream fs = null;
Stream xmlStream = null;
byte[] bytsXml;
int lenByts;

try
{
Assembly asmCurrent = Assembly.GetExecutingAssembly();

xmlStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(typeof(InterestCalculation).Namespace + ".BorrowFormulaConfig.ini");
bytsXml = new byte[xmlStream.Length];
using (fs = File.Create(_path))
{
while ((lenByts = xmlStream.Read(bytsXml, 0, bytsXml.Length)) > 0)
{
//向文件中写信息
fs.Write(bytsXml, 0, lenByts);
fs.Flush();
}
}
}
finally
{
if (fs != null)
fs.Close();

if (xmlStream != null)
xmlStream.Close();
}
}

后面看到观海看云

所以这个文件需要右键点击,在属性中选择生成操作为嵌入的资源即可。

posted @ 2017-03-03 11:41  ☆♂安♀★  阅读(760)  评论(0编辑  收藏  举报