I want to add linked files to a project with a environment variable in the path.
When trying with $(SourceLoc)\File.cs, the path is rejected.
When trying with %SourceLoc%\File.cs, the path is accepted but resolved to a full path.
I can close the project and edit the project file manually, add $(SourceLoc) to the path and it work fine. But isn’t there any easier way?
Update
I found out it could possibly be done with a tool window extensions and DTE. I havn’t tested it yet though.
Update
I have tried doing this with extensions now but it didn’t work either:
Solution2 soln;
Project prj;
soln = (Solution2)_dte.Solution;
ProjectItem prjItem;
prj = soln.Projects.Item(1);
prjItem = prj.ProjectItems.AddFromFile(@"%SourcePath%\MyClass.cs"); // fail
prjItem = prj.ProjectItems.AddFromFile(@"$(SourcePath)\MyClass.cs"); // fail
Darnit…
In Visual Studio you’re adding a file to a project using standard Windows Open File Dialog, thus $(x) doesn work, and %x% is being expanded to the full path.
So no, there is no other way then edit a project file manually.