如何让Visual Studio识别网络驱动器映射

时间:2016-11-10 11:31:02

标签: batch-file visual-studio-2015 cmd unc

我在项目中定义了以下Post-Build事件:

if "$(ConfigurationName)"=="Release" ("$(ProjectDir)PostBuildRelease.bat" "$(TargetDir)")

因此,当我在发布模式下构建项目时,将执行以下.bat文件:

PostBuildRelease.bat

CMD
SET parameter=%1
CD %1
ECHO "Copying temporary file..."
COPY FileDeleter.exe temp.exe
ECHO "Merging dependancies..."
"..\..\ILMerge.exe" /out:"FileDeleter.exe" /targetPlatform:"v4" "temp.exe" "Microsoft.WindowsAPICodePack.dll" "Microsoft.WindowsAPICodePack.ExtendedLinguisticServices.dll" "Microsoft.WindowsAPICodePack.Sensors.dll" "Microsoft.WindowsAPICodePack.Shell.dll" "Microsoft.WindowsAPICodePack.ShellExtensions.dll"
ECHO "Removing temporary file..."
DEL temp.exe

它只是将程序集复制到临时位置,将所需的依赖项合并到最终的可执行文件FileDeleter.exe中,然后删除临时文件。

当项目保存到本地驱动器时,此工作正常,但在将项目移动到网络驱动器后,我在发布模式下构建时出现这些错误:

'\\file\IT\Internal Apps\AppDev\Applications\WpfFileDeleter\WpfFileDeleter\bin\Release\'
CMD does not support UNC paths as current directories.
C:\Windows>"Copying temporary file..."
The system cannot find the file specified.
"Merging dependancies..."
'"..\..\ILMerge.exe"' is not recognized as an internal or external command,
operable program or batch file.
"Removing temporary file..."
Could Not Find C:\Windows\temp.exe

CMD抱怨不支持UNC路径。

但是,我知道有问题的驱动器(\\File)实际上已映射到Y:\驱动器 - 所以我可以通过定位Y:而不是{导航到CMD中的目录{1}}。

问题是 - 在将所有项目移动到此网络驱动器后,如何让Visual Studio默认识别此驱动器映射?

2 个答案:

答案 0 :(得分:1)

我已经知道批量dosnt就像越过网络目录,除非你把它添加为pushhd的驱动器。在网络上工作时,这对我来说很有魅力。

  

PUSHD是一个内部命令。如果禁用了Command Extensions,PUSHD命令将不接受网络(UNC)路径。“

来源: http://ss64.com/nt/pushd.html

答案 1 :(得分:0)

我能够使用this answer找到解决方案:

  1. 从Visual Studio解决方案中删除项目
  2. 右键单击解决方案"添加现有项目"
  3. 导航至Y:\folder\test文件,确保使用映射的驱动器导航至该文件(例如\\file\folder\test而不是TargetDir
  4. 现在添加项目后,将使用映射驱动器而不是\\file设置Team Explorer变量,这意味着构建后事件或批处理文件不需要进行任何更改。
  5. 另一个选项,就像我在VS中使用Team Foundation Services一样,是从Manage Connection - >中删除所有现有的本地git存储库。 Local Git Repositories - > Y:\,然后重新添加相同的位置,但在导航到该文件夹​​时,再次使用\\file代替TargetDir

    现在,我从这些存储库打开的任何项目都会自动使用映射驱动器设置其PUSHD路径。

    此处的其他答案也有效,但需要更改后期构建事件以使用硬编码的映射路径以及更改批处理文件以使用CD而不是artist.songs.distinct.pluck(:genre)