Visual Studio 解决方案路径环境变量 [英] Visual Studio Solution Path environment variable

查看:52
本文介绍了Visual Studio 解决方案路径环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

VS 是否有当前解决方案路径的环境变量?

Does VS have an environment variable for the path to the current solution?

例如有%PathToWebRoot%",一般设置为你VS项目目录下的WebSites"目录.它的值可以通过多种方式改变.我想知道是否有一个变量在每次加载解决方案以指向它的根时都会发生变化.

For example, there is "%PathToWebRoot%" which is generally set to the "WebSites" directory in your VS project directory. The value of it can be changed in any number of ways. I'm wondering if there's a variable that changes each time you load a solution to point to it's root.

我正在创建可能在不同机器上运行的单元测试,并且您必须在该方法之前设置的方向之一是 AspNetDevelopmentServerHost.当然,建议不要对它们进行硬编码,但推荐的环境变量不一定是您的网站所在的位置,在这种情况下也不是.

I'm creating unit tests that will potentially be run on different machines and one of the directions you have to set before the method is the AspNetDevelopmentServerHost. It's recommended not to hard code them, of course, but the recommended environment variable isn't necessarily where your site will be and isn't in this case.

推荐答案

VS 有很多宏变量可以在 VS 内工作.为您提供解决方案完整路径的方法称为 $(SolutionDir).但是,虽然这适用于构建前和构建后事件(以及解决方案的 MSBuild 文件中的 AFAIK),但这不是环境变量.如果您考虑一下,您不能有一个(全局)环境变量指向当前解决方案的路径",因为您可能打开了多个 VS 实例.

VS has a lot of Macro variables that work from within VS. The one that gives you the full path to the solution is called $(SolutionDir). However, while this works from the Pre- and Post-build events (and, AFAIK, in the solution's MSBuild file), this is not an environment variable. If you think about, you can't have a (global) environment variable that points to "the path to the current solution", since you may have more than one instance of VS open.

根据您的单元测试框架,您通常可以询问其执行上下文以获取当前目录.不过,这可能不会为您提供解决方案路径...

Depending on your unit testing framework, you can often ask it about its execution context to get the current directory. That may not give you the solution path, though...

这篇关于Visual Studio 解决方案路径环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆