简体   繁体   English

如何在 C# 程序集中嵌入 Xslt 文件?

[英]How to embed a Xslt file in a C# assembly?

I would like to embed a Xslt file in an assembly so that I can load the Xslt without having to read it from disk, and so that everything I need is contained within the exe.我想在程序集中嵌入一个 Xslt 文件,这样我就可以加载 Xslt 而不必从磁盘读取它,并且我需要的所有内容都包含在 exe 中。

i did this Xslt;我做了这个 Xslt; enter image description here在此处输入图像描述

C# C#

Assembly assembly = Assembly.GetExecutingAssembly(); 
Stream stream = assembly.GetManifestResourceStream("TimeSoft.Entities.Properties.Resources.general.Xslt");
StreamReader s = new StreamReader(stream);

I don't want to read the file.我不想读文件。 So I guess these codes are wrong.所以我猜这些代码是错误的。 What i want is just get the file path how can i do that?我想要的只是获取文件路径我该怎么做?

I have tried a test with a .NET framework 4.8 console app and an embedded file named sheet1.xsl in the project/assembly named XsltResourceNETFrameworkTest1 is found fine with using (var stream = assembly.GetManifestResourceStream("XsltResourceNETFrameworkTest1.sheet1.xsl")) .我已经尝试使用 .NET Framework 4.8 控制台应用程序进行测试,并且using (var stream = assembly.GetManifestResourceStream("XsltResourceNETFrameworkTest1.sheet1.xsl"))在名为XsltResourceNETFrameworkTest1的项目/程序集中找到了一个名为sheet1.xsl的嵌入式文件. So this seems to work, you just need to get the assembly name and file name right.所以这似乎可行,您只需要正确获取程序集名称和文件名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM