标签: embedded-resource

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

我有几个图像,我想嵌入到exe中.

当我将构建操作设置为嵌入式资源时, 我解决了代码中出现资源不可用的错误,并要求我将构建操作设置为资源

我尝试了几种不同的方法:

 <ImageSource x:Key="Image_Background">YearBook;component/Resources/Images/darkaurora.png</ImageSource>

 <ImageSource x:Key="Image_Background">Images/darkaurora.png</ImageSource>

 <ImageSource x:Key="Image_Background">pack://application:,,,/Resources/Images/darkaurora.png</ImageSource>
Run Code Online (Sandbox Code Playgroud)

此代码位于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.
Run Code Online (Sandbox Code Playgroud)

在代码中的不同位置我得到:

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'
Run Code Online (Sandbox Code Playgroud)

那么,我做错了什么?

.net c# wpf xaml embedded-resource

24
推荐指数
1
解决办法
5万
查看次数

我可以更改Google地图嵌入地图(iframe)中的标记吗?

我知道我可以使用Google Maps API来做到这一点,但您知道是否有办法更改嵌入式Google地图中的标记?

我想替换"B"按钮的默认"A" 按钮中间只有一个点标记.

iframe google-maps embedded-resource google-maps-markers

23
推荐指数
2
解决办法
6万
查看次数

如何读取可移植类库中的资源文件?

我有一个可移植的库,我用于Windows Phone应用程序.在同一个可移植库中,我有几个内容文件(Build Action = Content).

DataReader在Portable Library中创建了一个类,它应该向我返回一个流到内容文件.然而,下面的代码我一直取回nullGetManifestResourceStream.我究竟做错了什么?

public class DataReader
{
    public static Stream GetStream(string code)
    {
        string path = string.Format("./data/code-{0}.dat", code);
        return Assembly.GetExecutingAssembly().GetManifestResourceStream(path);
    }
}
Run Code Online (Sandbox Code Playgroud)

.net c# embedded-resource

22
推荐指数
3
解决办法
2万
查看次数

如何在单个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属性表中需要"构建操作"的设置.工作代码示例或指向教程项目的链接将是最好的.

c# embed internationalization embedded-resource

20
推荐指数
2
解决办法
2万
查看次数

如何将TXT文件作为资源添加到我的EXE文件中?

我有一个包含大约10,000行文本的TXT文件.我想在TMemo中显示这些行.但是我不想在我的程序中分发那个TXT文件.如何将它作为资源WITHIUT使用它集成到我的EXE文件中,stringtable {}因为这需要每行的标识符(所以我将不得不添加10000个标识符).

_

我有Delphi XE

delphi embedded-resource delphi-xe

20
推荐指数
1
解决办法
1万
查看次数

RazorEngine字符串布局和部分?

我像这样使用剃须刀引擎:

public class EmailService : IService
{
    private readonly ITemplateService templateService;

    public EmailService(ITemplateService templateService)
    {
        if (templateService == null)
        {
            throw new ArgumentNullException("templateService");
        }
        this.templateService = templateService;
    }

    public string GetEmailTemplate(string templateName)
    {
        if (templateName == null)
        {
            throw new ArgumentNullException("templateName");
        }
        Assembly assembly = Assembly.GetAssembly(typeof(EmailTemplate));
        Stream stream = assembly.GetManifestResourceStream(typeof(EmailTemplate), "{0}.cshtml".FormatWith(templateName));
        string template = stream.ReadFully();
        return template;
    }

    public string GetEmailBody(string templateName, object model = null)
    {
        if (templateName == null)
        {
            throw new ArgumentNullException("templateName");
        }
        string template = GetEmailTemplate(templateName); …
Run Code Online (Sandbox Code Playgroud)

c# embedded-resource razorengine

19
推荐指数
2
解决办法
1万
查看次数

如何将嵌入式资源作为字节数组读取而不将其写入磁盘?

在我的应用程序中,我使用CodeDom.Compiler从source.cs文件编译另一个程序,我在编译时嵌入了一些资源(exe和dll文件),使用:

 // .... rest of code

if (provider.Supports(GeneratorSupport.Resources))
{
    cp.EmbeddedResources.Add("MyFile.exe");
}
if (provider.Supports(GeneratorSupport.Resources))
{
    cp.EmbeddedResources.Add("New.dll");
}
// ....rest of code 
Run Code Online (Sandbox Code Playgroud)

在编译文件中,我需要将嵌入资源作为字节数组读取.现在我通过使用下面的函数和使用将资源提取到磁盘来实现这一点

File.ReadAllBytes("extractedfile.exe");
File.ReadAllBytes("extracteddll.dll");
Run Code Online (Sandbox Code Playgroud)

我使用此函数将两个文件解压缩到磁盘后执行此操作:

public static void ExtractSaveResource(String filename, String location)
{
    //  Assembly assembly = Assembly.GetExecutingAssembly();
    System.Reflection.Assembly a = System.Reflection.Assembly.GetExecutingAssembly();
    // Stream stream = assembly.GetManifestResourceStream("Installer.Properties.mydll.dll"); // or whatever 
    // string my_namespace = a.GetName().Name.ToString();
    Stream resFilestream = a.GetManifestResourceStream(filename);
    if (resFilestream != null)
    {
        BinaryReader br = new BinaryReader(resFilestream);
        FileStream fs = new FileStream(location, FileMode.Create); // say 
        BinaryWriter bw = new …
Run Code Online (Sandbox Code Playgroud)

.net c# codedom embedded-resource system-codedom-compiler

19
推荐指数
2
解决办法
2万
查看次数

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

我的资源文件有问题.

我有两个项目的解决方案.第一个项目包含ImageResource.resx带有我使用的图像的文件.Form此项目中的每个人都可以从设计器访问此文件.但我可以在设计器ImageResource.resx文件中看到从第二个项目中使用它(参考第二个项目存在).

我已将该ImageResource.resx文件添加为第二个项目的链接.我在设计师看到了它!但是当我在第二个项目中使用来自此资源的图像时,Visual Studio修改了我的原始文件(它设置名称空间,以及其他...),我的解决方案中断了.Visual Studio也告诉我,ImageResource.resx它存在于两个dll first_project.dllsecond_project.dll

任何人都可以帮助我如何在项目之间正确使用共享资源?

.net c# embedded-resource visual-studio solution-explorer

18
推荐指数
1
解决办法
2万
查看次数

无法使用GetManifestResourceStream()加载嵌入式资源

我正在使用/ linkres:compiler参数嵌入二进制文件,但是当我尝试使用以下命令加载它时:

System.Reflection.Assembly myAssembly = System.Reflection.Assembly.GetExecutingAssembly();
string[] names = myAssembly.GetManifestResourceNames(); // it is really there by its name "shader.tkb"
Stream myStream = myAssembly.GetManifestResourceStream( names[0] );
Run Code Online (Sandbox Code Playgroud)

这导致了一个

 Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'shader.tkb' or one of its dependencies. The system cannot find the file specified. ---> System.IO.FileNotFoundException: The system cannot find the file specified. (Exception from HRESULT: 0x80070002)
--- End of inner exception stack trace ---
at System.Reflection.RuntimeAssembly.GetResource(RuntimeAssembly assembly, String resourceName, UInt64& length, StackCrawlMarkHandle stackMark, Boolean skipSecurityCheck) …
Run Code Online (Sandbox Code Playgroud)

.net c# manifest embedded-resource

18
推荐指数
1
解决办法
3万
查看次数

指定内容的构建操作 - Nuget

告诉Nuget包将所有css文件添加为嵌入式资源(即构建操作是嵌入式资源)的最简单方法是什么.

我试图通过工具文件夹中的install.ps1来做到这一点,但仍然无法到达任何地方

注意:我从目录结构创建包(tools\content\lib)

这是我的install.ps1,它不起作用.

param($installPath, $toolsPath, $package, $project)
$MsbNS = @{msb = 'http://schemas.microsoft.com/developer/msbuild/2003'}    
function EmbeddContent($ProjectLink, [string]$XPath)
{
    $nodes = @(Select-Xml $XPath $ProjectLink -Namespace $MsbNS | Foreach {$_.Node})

    foreach ($node in $nodes)
    {   
    if($node.Include.StartsWith("Content\css"))
    {           
        $cet = $node.ownerdocument.CreateElement("EmbeddedResource")
        $cet.setAttribute("Include", $node.Include)
        $parent = $node.ParentNode          
        [void]$parent.RemoveChild($node)
        [void]$parent.Appendchild($cet)        
    }
    }
}
$project.Save()
$fileLocation = $project.FileName
$dte.ExecuteCommand("Project.UnloadProject");

$proj = [xml](gc $fileLocation)
Embeddcontent $fileLocation '//msb:Project/msb:ItemGroup/msb:Content'
$proj.Save($fileLocation)
Run Code Online (Sandbox Code Playgroud)

请帮忙 ..

c# powershell embedded-resource visual-studio nuget

17
推荐指数
1
解决办法
4612
查看次数