Tag: embedded resource

使用MSBuild构建后运行测试时出现MissingManifestResourceException(.mresource在清单中有路径)

我在命令行上使用MSBuild的构建服务器上的C#项目的嵌入资源有问题。 在Visual Studio中构建和运行测试时,该项目工作得很好,但是当从命令行运行MSBuild时,运行测试时会出现以下问题: System.Resources.MissingManifestResourceException:找不到适合指定文化或中性文化的任何资源。 确保“.Properties.Resources.resources”在编译时正确嵌入或链接到程序集“”,或者所有所需的附属程序集都是可加载和完全签名的。 System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo requestedCulture,Boolean)中的System.Resources.ManifestBasedResourceGroveler.GrovelForResourceSet(CultureInfo文化,Dictionary`2 localResourceSets,Boolean tryParents,Boolean createIfNotExists,StackCrawlMark和stackMark)中的System.Resources.ManifestBasedResourceGroveler.HandleResourceStreamMissing(String fileName)位于System.Resources.get_SomeResource()的System.Resources.ResourceManager.GetString(String name,CultureInfo culture)的System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture,Boolean createIfNotExists,Boolean tryParents)中的createIfNotExists,Boolean tryParents,StackCrawlMark和stackMark in \ Properties \ Resources.Designer.cs:第87行 我已将问题跟踪到生成的IL(我使用ildasm)。 在Visual Studio中进行bulding时,在程序集的清单中设置以下内容: .mresource public .Properties.Resources.resources { // Offset: 0x00000000 Length: 0x00000236 } 但是在使用MSBuild构建时会生成以下输出: .mresource public ‘../..//Build/_AnyCPU_Debug_Obj/.Properties.Resources.resources’ { // Offset: 0x00000000 Length: 0x00000236 } 因为可以看到资源的路径突然成为资源名称的一部分。 有没有人有任何想法如何解决这个问题?

如何读取,然后写入C#中的嵌入式资源

每当我尝试执行以下代码时,我都会收到错误“Stream is not writable”。 我知道在内存中仍然有对流的引用,但我不知道如何解决这个问题。 这两个代码块按顺序调用。 我认为第二个可能是函数调用或者调用堆栈中的两个更深层,但我认为这不重要,因为我在第一个块中有“using”语句应该自动清理流。 我确信这是C#中的常见任务,我只是不知道如何做到这一点…… string s = “”; using (Stream manifestResourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(“Datafile.txt”)) { using (StreamReader sr = new StreamReader(manifestResourceStream)) { s = sr.ReadToEnd(); } } … string s2 = “some text”; using (Stream manifestResourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(“Datafile.txt”)) { using (StreamWriter sw = new StreamWriter(manifestResourceStream)) { sw.Write(s2); } } 任何帮助将非常感谢。 谢谢! 安德鲁

以编程方式将资源加载为字节数组

我将图像添加为文件并将类型设置为资源(参见屏幕截图)如何在不使用resx文件等的情况下将其作为字节数组拉出来?

如何从资源文件中获取流对象(控制台应用程序/ Windows服务项目)

我正在创建一个Windows服务,我正在尝试访问我添加到资源文件中的一些文件,但我被卡住了,因为我不知道如何访问单个文件。 仅仅为了一些背景信息,这是我到目前为止所做的: 这是一个在调试模式下作为控制台应用程序运行的C#Windows服务应用程序,它可以帮助我进入代码。 我在根目录中添加了一个名为“Resources.resx”的资源文件。 在我的资源文件中,我使用可视化设计器/编辑器添加了一些jpg图像和html文件。 在我将图像和html文件添加到资源文件后,我项目中的一个新文件夹显示为“Resources”,其中包含我添加的所有文件。 在这个新文件夹中,我转到了每个文件的属性,并将Build Action更改为Embedded Resource。 (我不知道这是否有必要。我搜索的一些博客说要试试。) 项目的名称空间称为“MicroSecurity.EmailService”。 为了获取资源文件的名称,我使用了 的GetType()。Assembly.GetManifestResourceNames() 我得到以下内容 GetType()。Assembly.GetManifestResourceNames(){string [2]} string [] [0]“MicroSecurity.EmailService.Services.EmailService.resources”string [1]“MicroSecurity.EmailService.Resources.resources”string 从此我发现“MicroSecurity.EmailService.Resources.resources”是我想要使用的字符串(索引1)。 我使用此代码来获取流对象。 var stream = Assembly.GetExecutingAssembly()。GetManifestResourceStream(“MicroSecurity.EmailService.Resources.resources”); 当我在调试期间向此变量添加监视时,我可以看到诸如图像的元数据之类的内容等。 这是我被困的地方。 我想访问名为“logo.jpg”的图像。 这是我正在做的图像,但它不起作用。 var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(“MicroSecurity.EmailService.Resources.resources.logo.jpg”); 如何从logo.jpg文件中获取流? 更新: 感谢安德鲁,我能够弄清楚。 下面是我为演示项目编写的一些代码,以便研究资源文件如何工作而不是直接嵌入文件。 我希望这有助于其他人澄清差异。 using System; using System.Drawing; using System.IO; using System.Reflection; namespace UsingResourceFiles { public class Program { /// […]

如何在一个解决方案中的项目之间使用共享资源文件?

我有资源文件的问题。 我有两个项目的解决方案。 第一个项目包含ImageResource.resx文件,其中包含我使用的图像。 此项目中的每个Form都可以从设计器访问此文件。 但我可以在设计器ImageResource.resx文件中看到从第二个项目中使用它( 引用第二个项目 )。 我已将ImageResource.resx文件添加为我的第二个项目的链接。 我在设计师看到了它! 但是当我在第二个项目中使用来自此资源的图像时,Visual Studio修改了我的原始文件(它设置名称空间,以及其他…) ,我的解决方案中断了。 Visual Studio还告诉我, ImageResource.resx存在于两个dll的first_project.dll和second_project.dll 任何人都可以帮助我如何在项目之间正确使用共享资源?

如何在单个EXE中嵌入多语言* .resx(或* .resources)文件?

有很多教程如何创建多语言RESX文件以及如何使用AL.exe创建附属程序集,但我还没有找到工作示例如何在单个EXE文件中嵌入RESX / Resources / satellite-DLL文件并分发整个多语言应用程序就像这样的EXE。 我试图使用ilmerge.exe,但它看起来不适用于具有相同名称的多个DLL(文化卫星DLL具有相同的名称,最初驻留在以文化命名的不同子目录中)。 我也不知道如何创建ResourceManager实例来使用嵌入式资源。 我的目标是在封闭的,预定义的语言集之间实现动态切换。 我需要类/方法,它将获得文化字符串(即“de-DE”),资源名称(即“CancelText”)并返回基于嵌入式 resx / resource / dll的翻译文本。 我正在使用VS2008,请注意resx / resource files属性表中需要“构建操作”的设置。 工作代码示例或指向教程项目的链接将是最好的。

我们如何将嵌入式资源添加到在运行时从源文件编译的文件中

我正在编写一个小应用程序,它使用函数从源(.cs)代码文件编译文件: public static bool CompileExecutable(String sourceName) { //Source file that you are compliling FileInfo sourceFile = new FileInfo(sourceName); //Create a C# code provider CodeDomProvider provider = CodeDomProvider.CreateProvider(“CSharp”); //Create a bool variable for to to use after the complie proccess to see if there are any erros bool compileOk = false; //Make a name for the […]

在内容资源上调用的Application.GetResourceStream仍然返回null

以下是VS2010项目(Windows Phone)结构中与任务相关的部分: 代码正在从DummyMediaLibProvider.cs执行: public class DummyMediaLibProvider: IMediaLibProvider { … StreamResourceInfo albumArtPlaceholder = Application.GetResourceStream( new Uri(“../Images/artwork.placeholder.png”, UriKind.Relative)); artwork.placeholder.png 构建操作设置为内容 。 但是,每当我运行代码时, Application.GetResourceStream返回null。 资源无法读取内存的原因可能是什么? 我试图删除项目的obj目录,做了Clean和Rebuild,但到目前为止没有任何帮助。 更新: 如果我将Build Action:Resource应用于artwork.placeholder.png,我可以获得资源流。 PS这不是Application.GetContentStream的副本,因为上一次有扩展(particurarly .xml)相关问题,因此内容Uri返回null 。

尝试将Autofac加载为嵌入式程序集时出现FileNotFoundException

以前版本的Autofac工作,但由于他们切换到使其成为可移植类库,它将无法加载。 我尝试应用此处列出的修复程序(KB2468871),但它告诉我它不需要。 当我将Autofac.dll文件移动到与可执行文件相同的位置时,错误消失了。 当它从外部DLL加载它时,它加载正常。 为什么它不能作为嵌入式DLL工作? 这是例外: System.IO.FileNotFoundException: Could not load file or assembly ‘System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes’ or one of its dependencies. The system cannot find the file specified. Stack trace: at Autofac.Core.Registration.ComponentRegistration..ctor(Guid id, IInstanceActivator activator, IComponentLifetime lifetime, InstanceSharing sharing, InstanceOwnership ownership, IEnumerable`1 services, IDictionary`2 metadata) at Autofac.Core.Container..ctor() at Autofac.ContainerBuilder.Build(ContainerBuildOptions options) at MyApp.Configuration.Bootstrapper.Run(String[] args) […]

如何从XAML引用嵌入式资源?

我有几个图像,我想嵌入到exe中。 当我将构建操作设置为嵌入式资源时,我通过代码解决了资源不可用的错误,并要求我将构建操作设置为资源 我尝试了几种不同的方法: YearBook;component/Resources/Images/darkaurora.png Images/darkaurora.png pack://application:,,,/Resources/Images/darkaurora.png 此代码位于Resource文件中。 但没有一个工作,他们都抛出这个错误: Cannot convert the string ‘pack://application:,,,/Resources/Images/darkaurora.png’ into a ‘System.Windows.Media.ImageSource’ object. Cannot locate resource ‘resources/images/darkaurora.png’. Error at object ‘Image_Background’ in markup file ‘YearBook;component/Resources/ImageResources.xaml’ Line 4 Position 6. 在代码中的不同位置我得到: the file ‘YearBook;component/Resources/Images/shadowdrop.png’ is not a part of the project or its ‘Build Action’ property is not set to ‘Resource’ 那么,我做错了什么?