Replies: 9 comments
-
I don't think that this really belongs as a part of the language specification. The compiler knows nothing about the project structure and certainly nothing about non-C# files intended to support the project. For this I might prefer a tool that can run as a part of the build that would output an |
Beta Was this translation helpful? Give feedback.
-
You could easily do this with a T4 file and Visual Studio macros. Of course, if you're not using Visual Studio you'd have to find another solution that involves the build agent. |
Beta Was this translation helpful? Give feedback.
-
@HaloFour How does the compiler not know about project files? I thought you can specify which files are embedded resources, files to include for compile, etc. Perhaps I misunderstood that feature? I thought that those files become visible for the compiler. Though I also agree that it would be interesting to see a tool that can output an internal class containing helpful project properties. |
Beta Was this translation helpful? Give feedback.
-
The compiler has no knowledge of the project system that manages the files (it doesn't know what a For some files, such as resx, the compiler doesn't get the file itself and instead gets a |
Beta Was this translation helpful? Give feedback.
-
Also, returning absolute paths would likely be a non-starter. This would prevent a compiled-app from being portable (couldn't ever use the keyword in a program where you could potentially run on Linux/Mac, if it was compiled on Windows). Returning relative paths also has issues. It could potentially break in certain cross-platform scenarios (where the path-separator character was different) or even break when used with network paths. |
Beta Was this translation helpful? Give feedback.
-
@tannergooding Thanks for more clarification of the compilers visibility. I figured it would be a cross platform concern but also figured that something could be done to handle those situations. Well I think I have enough information to understand that this is out of scope for language specification. |
Beta Was this translation helpful? Give feedback.
-
I could imagine writing a simple helper method in the form of You could also do something like @HaloFour suggested and dynamically generate a source file that exposes the project system structure as properties/etc (this could be done as an MSBuild task). |
Beta Was this translation helpful? Give feedback.
-
I'd make an extension method on string: |
Beta Was this translation helpful? Give feedback.
-
@HaloFour suggestion is, in my opinion, the preferred route. The problem with an extension method or I was proposing more of a solution that the compilation could potentially break and throw an error because the file no longer existed within the project or known build context. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
This request is mostly for convenience, maybe not as convenient and helpful as nameof.
Has a keyword ever been proposed to return a project files relative or absolute path? I would like to see a new keyword added maybe named staticfile() or projfile() and would be used in the below case:
This would avoid:
This avoids manipulating strings and possibly renamed files. So if a file get renamed within the IDE, it can recursively update files that had the staticfile keyword wrapped on the old named file.
Thoughts?
Beta Was this translation helpful? Give feedback.
All reactions