C
C#

help

✅ Extracting files that are in your project into a certain directory when compiled into an exe file?

UUUnknown User12/26/2022
Message Not Public
Sign In & Join Server To View
Eero12/26/2022
You need to set the files as embedded resources, get their manifest resource stream, and copy that stream to a specified output stream
UUUnknown User12/26/2022
Message Not Public
Sign In & Join Server To View
Eero12/26/2022
I think i gave you enough things to Google
Aarion12/26/2022
pyfile.py -> Right Click -> Properties -> Build Action: "Embedded resource"
string[] resourceNames = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceNames();

string yourLikelyPythonFilePath = resourceNames.FirstOrDefault(name => name.Contains("pyfile.py"));

if (yourLikelyPythonFilePath == null)
{
throw new Exception("Could not find the python file in the resources");
}

System.IO.Stream stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(yourLikelyPythonFilePath);

using (System.IO.FileStream fileStream = new System.IO.FileStream("pyfile.py", System.IO.FileMode.Create, System.IO.FileAccess.Write))
{
stream.CopyTo(fileStream);
}
string[] resourceNames = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceNames();

string yourLikelyPythonFilePath = resourceNames.FirstOrDefault(name => name.Contains("pyfile.py"));

if (yourLikelyPythonFilePath == null)
{
throw new Exception("Could not find the python file in the resources");
}

System.IO.Stream stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(yourLikelyPythonFilePath);

using (System.IO.FileStream fileStream = new System.IO.FileStream("pyfile.py", System.IO.FileMode.Create, System.IO.FileAccess.Write))
{
stream.CopyTo(fileStream);
}
Eero12/26/2022
Hey yeah let's spoon feed from chatgpt
Aarion12/26/2022
wasnt from chat gpt though sadge
Eero12/26/2022
Writing out type names with namespaces and using old using statements says otherwise
Aarion12/26/2022
Well, he's likely a new person to C#, will likely get stuck at "Where is this from, why compile error?" To avoid that convo, type out the full namespace same exact thing goes for
resourceNames.FirstOrDefault(name => name.Contains("pyfile.py"));
resourceNames.FirstOrDefault(name => name.Contains("pyfile.py"));
though if u have that little faith, u do u
Eero12/26/2022
Or just add it as a using...? You're missing using System.Linq; as well so, completely pointless Just don't spoon feed a complete solution Finding a solution to something as simple as this is an essential skill to learn for beginners You don't learn anything by just copy pasting
Aarion12/26/2022
Not many ppl care about reflection enough to go read 10 docs pages about it and 5 yt videos to complete a simple thing
Eero12/26/2022
It's like 3 Google searches. How to set it as an embedded resource, how to get the resource stream (i literally even spelled it out so they can search it easier), and how to copy it to an output stream It's really not that hard to Google that. The first result of each of those searches will probably be good enough
Aarion12/26/2022
You wouldnt be giving much help when u just say "Just google it" though, at that point i would actually just recommend to sign up for openai and ask chatgpt everything "How do i do x in c#?" just google it
Eero12/26/2022
There are things that warrant that. This is one of those things
Aarion12/26/2022
I'll agree to disagree <:poi_shrug:582941309174546569>
UUUnknown User12/26/2022
2 Messages Not Public
Sign In & Join Server To View
Aarion12/26/2022
new System.IO.FileStream("pyfile.py"...
new System.IO.FileStream("pyfile.py"...
if you dont specify an absolute path, it uses a relative path which is the Working Directory iirc
UUUnknown User12/26/2022
2 Messages Not Public
Sign In & Join Server To View

Looking for more? Join the community!

Want results from more Discord servers?
Add your server
Recommended Posts
❔ xmlhow to make to my program reads only elements inside "Officer I"?❔ hey i need guidance from a .net expertplease❔ reverse of RemoveAt[index]hi, so my problem is that im itterating through a list of 10 questions, and each time the user has cSome namespace and class questions..```css namespace Cool { class VeryCool { static void main(string[] args) { ✅ Texas holdem pokerHi, I need help with my project to school. My task is to create Texas holdem poker. But I dont know ❔ Sockets - TCPI'm going to implement a TCP listener for RF-V48 (4G GPS Tracking Bracelet) for elders. The device i❔ Problems with colliders...Context: when a game object with tag "Player" touch other object, print in console "Func". But that ❔ .NET6 Selenium 4. it’s possible to use Navigate.GoToUrl(url) using http Post?Hi, Im was searching around a solution or approach for use a POST method instead GET when using GoTo❔ Multi-tenant == Roles ?I need clarification whether the RoleManager in IdentityDbContext that manages roles for user author❔ Custom template not showing upI'm trying to create a new custom .csproj template for .NET 7, but I can not seem to get it to show ❔ Is it possible to put a method into a variable and call the variable?like this:❔ Getting error 500 on form post (using fetch)I'm trying to do a form post (posting a model), but my controller is not being called. When I check❔ Need some help with logicim trying to make a the total defence and attack statistics equal to 35 (they are randomised for 6 p❔ when instancing a class, why do you need to write the class name twice?This just seems sort of redundant to me, is there a reason? ```csharp ClassName objectName = new Cl❔ JWT token claims not working anymore after deploying application to Azure web app.The code that is working inside a controller locally but not working when deployed on azure Attempt✅ Dapper InsertAsync fails on Postgres with relation does not existHello, I am currently trying to run Dapper CRUD operations (Dapper.Contrib.Extensions) on a database❔ Key press on ButtonI want to make a tool where you press a button so that a key is pressed❔ How bad is this Linq code?```csharp if (getBeginningContent == false) dynContentList = await _context.DynamicContents ❔ Please Help! When I flip my character he moves backwardsHey guys... so I have a problem with my player controller... when I flip it to the other direction m✅ Source Generator, dynamic assembly not added.I have the following code: ```cs var assemblyName = new AssemblyName("MyAssembly");