What's an easy way to access prebuild macros such as $(SolutionDir) and $(DevEnvDir) from code in C#?

主宰稳场 提交于 2019-12-07 16:34:38

问题


Right now I'm thinking write the paths to a file in the pre-build event and then read from that file in the code, but I'm wondering if there's an easier more elegant way.

edit: This is sort of a follow up to Help with one step build all projects + installer (.NET + WiX) since I didn't really get an answer to that, seeing if I can get an answer to a simpler question.


回答1:


Here's a dirty hack: dump them to a file.

  1. Add an action to the pre-build events to output your solution's path to a file:

    echo $(SolutionDir) > SolutionDirFile.txt

  2. Read the file SolutionDirFile.txt in your C# code.




回答2:


This is just a guess, but I think one of the ways you could get this information into the file at compile-time is by using something like PostSharp. Basically, get some sort of preprocessor to get the data for you, and then simply embed it in your assembly.



来源:https://stackoverflow.com/questions/481063/whats-an-easy-way-to-access-prebuild-macros-such-as-solutiondir-and-devenv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!