我有几个图像,我想嵌入到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)
那么,我做错了什么?
我有一个可移植的库,我用于Windows Phone应用程序.在同一个可移植库中,我有几个内容文件(Build Action = Content).
我DataReader在Portable Library中创建了一个类,它应该向我返回一个流到内容文件.然而,下面的代码我一直取回null的GetManifestResourceStream.我究竟做错了什么?
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) 有很多教程如何创建多语言RESX文件以及如何使用AL.exe创建附属程序集,但我还没有找到工作示例如何在单个EXE文件中嵌入RESX/Resources/satellite-DLL文件并分发整个多语言应用程序就像这样的EXE.
我试图使用ilmerge.exe,但它看起来不适用于具有相同名称的多个DLL(文化卫星DLL具有相同的名称,最初驻留在以文化命名的不同子目录中).
我也不知道如何创建ResourceManager实例来使用嵌入式资源.
我的目标是在封闭的,预定义的语言集之间实现动态切换.我需要类/方法,它将获得文化字符串(即"de-DE"),资源名称(即"CancelText")并返回基于嵌入式 resx/resource/dll的翻译文本.
我正在使用VS2008,请注意resx/resource files属性表中需要"构建操作"的设置.工作代码示例或指向教程项目的链接将是最好的.
我有一个包含大约10,000行文本的TXT文件.我想在TMemo中显示这些行.但是我不想在我的程序中分发那个TXT文件.如何将它作为资源WITHIUT使用它集成到我的EXE文件中,stringtable {}因为这需要每行的标识符(所以我将不得不添加10000个标识符).
_
我有Delphi XE
我像这样使用剃须刀引擎:
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) 在我的应用程序中,我使用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) 我的资源文件有问题.
我有两个项目的解决方案.第一个项目包含ImageResource.resx带有我使用的图像的文件.Form此项目中的每个人都可以从设计器访问此文件.但我可以在设计器ImageResource.resx文件中看到从第二个项目中使用它(参考第二个项目存在).
我已将该ImageResource.resx文件添加为第二个项目的链接.我在设计师看到了它!但是当我在第二个项目中使用来自此资源的图像时,Visual Studio修改了我的原始文件(它设置名称空间,以及其他...),我的解决方案中断了.Visual Studio也告诉我,ImageResource.resx它存在于两个dll first_project.dll和second_project.dll
任何人都可以帮助我如何在项目之间正确使用共享资源?
我正在使用/ 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) 告诉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# ×8
.net ×5
codedom ×1
delphi ×1
delphi-xe ×1
embed ×1
google-maps ×1
iframe ×1
manifest ×1
nuget ×1
powershell ×1
razorengine ×1
wpf ×1
xaml ×1