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

Batch file 如何让Visual Studio识别网络驱动器映射,batch-file,visual-studio-2015,cmd,unc,Batch File,Visual Studio 2015,Cmd,Unc,我在项目中定义了以下生成后事件: 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 E

我在项目中定义了以下生成后事件:

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:
而不是
\\File\
来导航到CMD中的目录


问题是-在我的所有项目都移动到此网络驱动器后,如何让Visual Studio在默认情况下识别此驱动器映射

我了解到,批处理并不喜欢通过网络目录,除非您使用
pushhd
将其添加为驱动器。在网络上工作时,这对我来说就像一个魅力

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

资料来源:

我能够通过以下方法找到解决方案:

  • 从Visual Studio解决方案中删除项目
  • 右键单击解决方案并“添加现有项目”
  • 导航到
    .csproj
    文件,确保使用映射的驱动器导航到该文件,(即
    Y:\folder\test
    而不是
    \\file\folder\test
  • 现在,添加项目后,将使用映射驱动器而不是
    \\file
    设置
    TargetDir
    变量,这意味着无需对生成后事件或批处理文件进行任何更改

  • 另一个选项,就像我在VS中使用Team Foundation Services一样,是从<代码> Team Explorer < /代码> > >代码>管理连接> /COD> >代码>本地GIT存储库< /C> >,然后重新添加相同的位置,但再次导航到文件夹时,请使用<代码> y:\/Cort>而不是<代码> \file < /代码。>

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



    这里的另一个答案也有效,但需要将生成后事件更改为使用硬编码的映射路径,以及将批处理文件更改为使用
    PUSHD
    而不是
    CD

    为其指定绝对url。例如,Y:\FileDeleter.exe以驱动器开头。您应该具有该驱动器的读写权限。如果以admi身份运行n您只能访问映射为admin的驱动器。@karman感谢您的评论-请参阅下面的答案和我的解决方案评论。我想知道是否有任何方法可以让VS自动将当前目录设置为映射的url这与在生成后事件中传递绝对url一起工作:
    if“$(ConfigurationName)“==”Release“(“$(ProjectDir)PostBuildRelease.bat”“Y:\Internal Apps\AppDev\Applications\wpfiledeleter\wpfiledeleter\bin\Release\”
    很高兴我能提供帮助:)我还添加了我自己的答案,您可能会发现这很有用