Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Friday, July 3, 2015 3:21 AM
Hi guys,
Do you know an easy way for retrieving the value of $(solutiondir) variable during execution time of a C# console application? The reason I am asking this is because I would like to retrieve one path that points to a file which is relative to $(solutiondir) and it is used by my program.
Thanks,
Michael Giannakopoulos
All replies (1)
Friday, July 3, 2015 5:49 AM ✅Answered | 1 vote
Probably it is more appropriate to copy the file to output directory (or subfolder). If the file is in your project, then see its “Copy to Output Directory” value in Properties window. Or specify a copying command line in “Build Events” tab of project’s properties. In this case your executable will not depend on sources and can be delivered easier. The current executable folder can be determined programmatically.
If you really want the value in C#, then consider this approach. Add a new empty code file to your project. For example: MyFile.cs. Then go to the Properties of your project, to “Build Events”, and specify this pre-build command line:
@echo public static class MyClass { public const string SolutionDir = @"$(SolutionDir)"; } > "$(ProjectDir)MyFile.cs"
After the first build you can access the variable named MyClass.SolutionDir.