C
C#ā€¢2y ago
CrosRoad95

ā” Reading file from the folder where .csproj is

How can i read files from folder where .csproj is? just like webapps allow to do, they do not copy files
Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
don't working
4 Replies
CrosRoad95
CrosRoad95OPā€¢2y ago
for simplicity let's say they are .html but i need to change them at runtime for easier debugging folder would looks like this:
index.html // "copy to output directory": "do not copy"
project.csproj
program.cs // File.ReadAllText("index.html")
index.html // "copy to output directory": "do not copy"
project.csproj
program.cs // File.ReadAllText("index.html")
because i want to at runtime change content and be able to refresh otherwise i have to open some /bin/net7/ folder to edit them what is really invonvinient
WhiteBlackGoose
WhiteBlackGooseā€¢2y ago
so you want to change an html file?
CrosRoad95
CrosRoad95OPā€¢2y ago
yes, at runtime but then i need to copy file again back just tell me how can i do this šŸ˜„ if idea end up being wrong, i will change later i need it only for debugging i assume i can set "current directory" to be ../../../ or smth like this ^ i will do this only for some functions, they will in debug seek for files in ../../../ folder Environment.CurrentDirectory - is ending always /bin/debug/net7/ ? sometimes seen it is slightly different i mean, i need to go 3 folders up, hope it doesn't change though there is some magic global variable holding path of .csproj šŸ˜„ one more question, how the hell can i configure "CopyToOutputDirectory" to copy entire folder?
<None Update="myFiles\*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="myFiles\*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
??? yea, recursive does it copy files only when they has changed? it means it may behave better with large files right now it's only 20KB in total, but i assume as number and size will growth, i will need to wait longer to start debugging
<None Update="MyFiles\**\*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="MyFiles\**\*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
right? as i said, i will create some "MyFilesProvider" which holds root directory, in debug it will be "../../../", in release the current directory i'm not doing standard web or console app šŸ˜›
Accord
Accordā€¢2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server