简体   繁体   English

Visual Studio(C#)使用环境变量生成输出路径

[英]Visual Studio (C#) Build Output path using environmental variables

Is it possible to use environmental variables in the build output path in VS 2008 (et al)/ I'm trying to find a solution where several developers on my team using both Windows XP & 7 and all with different Windows logons, can all modify projects and common referenced dll's (source held on Source Safe) and not screw up the relative paths? 是否可以在VS 2008中在构建输出路径中使用环境变量(等)/我正试图找到一种解决方案,使我团队中的几个开发人员同时使用Windows XP和7以及所有使用不同Windows登录名的人都可以修改项目共同引用的dll(源代码保存在Source Safe上),并且不会弄乱相对路径? I've tried such things as %userprofile% and $(userprofile). 我已经尝试过诸如%userprofile%和$(userprofile)之类的事情。

I've looked into post build events but these do not really seem to provide an anawer to my problem. 我研究了构建后事件,但是这些似乎并没有真正解决我的问题。 Sadly I'm not in the position to use 3rd party add-ons either as these will be non-commercial and it's nearly impossible to get authorization for any licences for them. 遗憾的是,我也无法使用第三方加载项,因为它们将是非商业性的,并且几乎不可能获得任何许可证。

(Similar unanswered question at Output path for build in visual studio 2010 ) 在Visual Studio 2010中用于构建的“输出”路径上类似的未解决的问题)

You need to open the csproj file in a text editor and manually enter your environment variables in the OutputPath section. 您需要在文本编辑器中打开csproj文件,并在OutputPath部分中手动输入环境变量。 Visual Studio escapes the '$', '(' and ')' when you try to do this from the IDE. 当您尝试从IDE中执行此操作时,Visual Studio会转义'$','(('和')'。

I've used the subst command to accomplish this sort of thing in the past. 过去,我已经使用了subst命令来完成这种事情。 Essentially all project references define paths in relation to a known drive letter like R:\\MyProject\\outputs . 基本上,所有项目引用都定义与已知驱动器号(例如R:\\MyProject\\outputs相关的路径。

Then every developer can map the R: drive (or whatever) to the folder structure particular to their environment. 然后,每个开发人员都可以将R:驱动器(或其他驱动器)映射到特定于其环境的文件夹结构。 As long as the folder structure beneath the mapped drive is the same, the location of that mapped folder can vary between machines, builds, and users. 只要映射的驱动器下面的文件夹结构相同,该映射的文件夹的位置就可以在计算机,内部版本和用户之间变化。

This works well as developers can then set up their environment with a simple batch file and easily switch between branches, projects etc and relative pathing within the projects is not broken. 这非常有效,因为开发人员可以使用简单的批处理文件设置环境,并轻松在分支,项目等之间切换,并且项目内的相对路径不会中断。

PaulTee, Is it a longshot to ask you try directory replication? PaulTee,问您尝试目录复制是否很困难? Like Dropbox/Synctoy and other tools that invokes a file-copy from choosen location to the expected shared location? 像Dropbox / Synctoy以及其他从选定位置调用文件副本到预期共享位置的工具?

In your situation, I would love to use the built-in environment variables. 在您的情况下,我很想使用内置的环境变量。 Probably there are a way to make it work, but until then i would go for such a solution. 也许有一种方法可以使它起作用,但是在那之前我会寻求这样的解决方案。 I would also have in mind that different users compiling to same directory, would make conflicts with both file versions and file locks (used by other user). 我还要记住,不同的用户编译到同一目录会与文件版本和文件锁(由其他用户使用)产生冲突。

If you don't mind the extra copies, you could add post-build event that copies the project outputs to a commonly-agreed location for shared dlls, and everyone uses a non-relative reference to that location. 如果您不介意多余的副本,则可以添加构建后事件,该事件将项目输出复制到共享dll的通用位置,并且每个人都使用对该位置的非相对引用。 It would still, though, require standardization of that target location, so maybe it is not what you are looking for. 不过,它仍然需要对该目标位置进行标准化,因此也许这不是您想要的。 (example below would allow for drive letter independence at least) (以下示例至少允许独立于驱动器号)

copy $(TargetPath) \\dependencies 复制$(TargetPath)\\ dependencies

While I don't quite understand what you're asking for, it sounds like symlinked directories will help -- you can configure the solution to output to some folder that will be symlinked to arbitrary locations on each individual box. 虽然我不太了解您的要求,但听起来像符号链接目录会有所帮助-您可以配置解决方案以输出到一些将符号链接到每个单独框上任意位置的文件夹。

http://en.wikipedia.org/wiki/NTFS_symbolic_link http://en.wikipedia.org/wiki/NTFS_symbolic_link

ghost edit - mklink is apparently new in 7, but older versions still support it (Russinovich to the rescue once again): 幻影编辑 -mklink显然是7中的新功能,但较旧的版本仍支持它(Russinovich再次进行救援):

http://technet.microsoft.com/en-us/sysinternals/bb896768 http://technet.microsoft.com/zh-cn/sysinternals/bb896768

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM