Got an annoying problem here. I\'ve got an NHibernate/Forms application I\'m working through SVN. I made some of my own controls, but when I drag and drop those (or view som
I've finally figured this one out. This will work for any Visual Studio version, does not rely on EnvDTE, and solves the original problem presented here.
In your project settings, under "Build Events", add the following "Pre-build event command line":
echo $(SolutionDir) > ..\..\solutionpath.txt
Build the project once. The file will be created in your project root.
In solution explorer, click "Show All Files" and "Refresh"
Add solutionpath.txt to your solution
Right click solutionpath.txt, click properties. Change your build action to "Embedded Resource"
Use the following code to get your solution path.
string assemblyname = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
string path = "";
using (var stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(assemblyname + ".solutionpath.txt"))
{
using (var sr = new StreamReader(stream))
{
path = sr.ReadToEnd().Trim();
}
}
Because this is a pre-build event, the file does not need to exist before the build is started, so it is compatible with source-control and doesn't have any obvious issues.