更改Ram盘的Visual Studio构建路径 [英] Change Visual studio build path for Ram disk

查看:69
本文介绍了更改Ram盘的Visual Studio构建路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前我拥有Visual Studio 17 V 15.4.2

Currently I have Visual Studio 17 V 15.4.2

是否可以为项目设置不同的构建路径?例如代替

Is it possible to set different build path for projects? for example instead of

C:\ Users \ [用户名] \ source \ repos \ [MyProject] \ [bin | obj]

继续前进

M:\ Users \ [用户名] \ source \ repos \ [MyProject] \ [bin | obj]

请注意,它本身的项目位于 C 内部,但是临时文件已移动到其他位置.我有一个 M 驱动器,它是一个16GB的ram磁盘.

note that project it self is inside C but temporary files are moved somewhere else. I have drive M which is a 16GB ram disk.

使用RAM磁盘的好处:(诱使我这样做的原因)

Benefits of using RAM disk:(reasons that is tempting me to do this)

  • 更快的构建时间(无实际IO)

  • faster build times (no real IO)

SSD不会因重复重建而耗尽.

SSD doesn't wear out with repetitive rebuilds.

项目从本质上被清理(带来了以下好处)

projects are inherently cleaned up (which brings following benefits)

共享速度更快,您的项目不会充满不必要的文件,因此您可以轻松地与其他人共享文件夹.(代码大小通常小于1MB,但构建对象可以超过1GB)

share faster, your projects are not filled with unnecessary files so that you can easily share folders with others. (code size is usually less than 1MB but build objects can go beyond 1GB)

快速备份,出于同样的原因,您的项目文件夹也始终保持清理状态,因此您可以更快地备份项目.(尤其是当您有许多项目时,例如,您将仅备份100MB而不是10GB)

fast backups, for same reason your project folders always remain cleaned up and you can backup project much faster. (especially when you have many projects, eg. you would only backup 100MB istead of 10GB)

创建锁定文件的机会较小.在这种情况下,格式化ramdisk比使用VS设置或重新启动它要容易得多(这会导致构建不同步,错误等).

less chance of creating locked files. (which cause build desync, errors etc) in that case formatting ramdisk is easier than mucking with VS settings or restarting it.

缺点:

  • 您需要更多的RAM,以我为例,我有32GB的存储空间,可以为它保留16GB的存储空间.

  • you need much more RAM, in my case I have 32GB which I can spare 16GB for it.

如果重置VS或计算机,则会丢失已编译的对象,并且必须重新构建(一次)

if you reset VS or computer you loose compiled objects and you have to rebuild (once)

但是使用RAM磁盘的好处明显加重了它的缺点.

but benefits of using RAM disk clearly overweight its drawbacks.

好吧,现在我已经合理地说服了你为什么我要这个给我路径:)

Ok, now that I convinced you reasonably why I want this give me paths :)

推荐答案

可以更改应使用bin-path和obj-path的项目文件(至少对于.NET应用程序而言).但是您需要在每个项目上手动更改此设置.而且,如果您检查这些更改,可能会给尝试构建的其他人造成问题.

It is possible to change the project files (at least for .NET applications) which bin- and obj-path should be used. But you need to change this manually on every project. And if you check in these changes it might cause problems for someone else that is trying to build.

相反,您将bin和obj目录更改为指向虚拟磁盘的符号链接.这不会影响您的项目和解决方案文件(除了git可能将此链接视为文件,因此您可能希望将这些链接添加到.gitignore中.)

Instead you change the bin- and obj-directories to be a symbolic link to a ramdisk. This will not affect your project and solution files (except that git might treat this links as file so you might want to add these to your .gitignore).

我创建了两个Powershell脚本来进行管理.我在解决方案文件所在的目录中运行这些文件.请注意,运行这些目录时将删除bin-和obj目录.

I’ve created two Powershell scripts to manage this. I’m running these in the same directory as the solution file. Be aware that the bin- and obj directories will be removed when you are running these.

此脚本将删除csproj文件所在的所有目录中的bin文件夹和obj文件夹,并将其替换为符号链接:

This script will remove bin- and obj-folders in all directories where these is a csproj-file and replace them with symbolic links:

$ramDiskDrive = "R:"

# Find all project files...
$projectFiles = Get-ChildItem -Filter *.csproj -Recurse 
# Get project directories
$projectDirectories = $projectFiles | ForEach-Object { $_.DirectoryName } | Get-Unique


# Create a bin-directory on the RAM-drive
$projectDirectories | ForEach-Object { New-Item -ItemType Directory -Force -Path "$ramDiskDrive$($_.Substring(2))\bin" } 

# Remove existing bin-directories
$projectDirectories | ForEach-Object { Remove-Item "$($_)\bin" -Force -Recurse }

# Link bin-directories to ramdisk
$projectDirectories | ForEach-Object { cmd /c mklink /D "$($_)\bin" "$ramDiskDrive$($_.Substring(2))\bin" }


# Create a obj-directory on the RAM-drive
$projectDirectories | ForEach-Object { New-Item -ItemType Directory -Force -Path "$ramDiskDrive$($_.Substring(2))\obj" } 

# Remove existing obj-directories
$projectDirectories | ForEach-Object { Remove-Item "$($_)\obj" -Force -Recurse }

# Link obj-directories to ramdisk
$projectDirectories | ForEach-Object { cmd /c mklink /D "$($_)\obj" "$ramDiskDrive$($_.Substring(2))\obj" }

此脚本将删除符号链接:

This script will remove the symbolic links:

# Find all project files...
$projectFiles = Get-ChildItem -Filter *.csproj -Recurse 
# Get project directories
$projectDirectories = $projectFiles | ForEach-Object { $_.DirectoryName } | Get-Unique


# Unlink bin-directories to ramdisk
$projectDirectories | ForEach-Object { cmd /c rmdir "$($_)\bin"   }

# Unlink obj-directories to ramdisk
$projectDirectories | ForEach-Object { cmd /c rmdir "$($_)\obj"   }

如果两次运行相同的脚本,则会收到错误消息,但是可以忽略这些错误消息.

If you are running the same script twice you will get error messages, but these could be ignored.

所有这些,从我的经验来看,使用RAM磁盘而不是SSD驱动器没有太大区别.它速度更快,但没有您期望的那么快.

All this said, from my experience there is no major difference to use a RAM-disk instead of an SSD-drive. It is faster but not that much as you might expect.

这篇关于更改Ram盘的Visual Studio构建路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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