如何让 Visual Studio 识别网络驱动器映射
How to get Visual Studio to recognise a network drive mapping
我的项目中定义了以下 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 中的目录\file\
.
问题是 - 在我的所有项目都已移动到此网络驱动器之后,如何让 Visual Studio 默认识别此驱动器映射?
我了解到批处理不喜欢通过网络目录,除非您使用 pushhd
将其添加为驱动器。在网络上工作时,这对我来说就像一个魅力。
PUSHD is an internal command. If Command Extensions are disabled the PUSHD command will not accept a network (UNC) path."
我能够使用 找到解决方案:
- 从 Visual Studio 解决方案中删除项目
- 右键单击解决方案并 "Add existing project"
- 导航到
.csproj
文件,确保使用映射的驱动器导航到它,(即 Y:\folder\test
而不是 \file\folder\test
)
- 现在一旦添加了项目,
TargetDir
变量将使用映射的驱动器而不是 \file
来设置,这意味着 post-build 事件不需要更改或批处理文件。
另一种选择,因为我在 VS 中使用 Team Foundation Services,是从 Team Explorer
-> Manage Connection
-> Local Git Repositories
中删除所有现有的本地 git 存储库然后重新添加相同的位置,但在导航到文件夹时再次使用 Y:\
而不是 \file
。
现在,我从这些存储库中打开的任何项目都会自动使用映射驱动器设置其 TargetDir
路径。
这里的另一个答案也有效,但需要更改 post-build 事件以使用硬编码映射路径以及更改批处理文件以使用 PUSHD
而不是 CD
。
我的项目中定义了以下 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 中的目录\file\
.
问题是 - 在我的所有项目都已移动到此网络驱动器之后,如何让 Visual Studio 默认识别此驱动器映射?
我了解到批处理不喜欢通过网络目录,除非您使用 pushhd
将其添加为驱动器。在网络上工作时,这对我来说就像一个魅力。
PUSHD is an internal command. If Command Extensions are disabled the PUSHD command will not accept a network (UNC) path."
我能够使用
- 从 Visual Studio 解决方案中删除项目
- 右键单击解决方案并 "Add existing project"
- 导航到
.csproj
文件,确保使用映射的驱动器导航到它,(即Y:\folder\test
而不是\file\folder\test
) - 现在一旦添加了项目,
TargetDir
变量将使用映射的驱动器而不是\file
来设置,这意味着 post-build 事件不需要更改或批处理文件。
另一种选择,因为我在 VS 中使用 Team Foundation Services,是从 Team Explorer
-> Manage Connection
-> Local Git Repositories
中删除所有现有的本地 git 存储库然后重新添加相同的位置,但在导航到文件夹时再次使用 Y:\
而不是 \file
。
现在,我从这些存储库中打开的任何项目都会自动使用映射驱动器设置其 TargetDir
路径。
这里的另一个答案也有效,但需要更改 post-build 事件以使用硬编码映射路径以及更改批处理文件以使用 PUSHD
而不是 CD
。