未验证 提交 d45d3222 编写于 作者: J Joey Robichaud 提交者: GitHub

Merge pull request #40143 from Therzok/patch-2

Allow overriding the cache path for the default persistent storage se…
......@@ -29,6 +29,16 @@ public DefaultPersistentStorageLocationService()
public virtual bool IsSupported(Workspace workspace) => false;
protected virtual string GetCacheDirectory()
{
// Store in the LocalApplicationData/Roslyn/hash folder (%appdatalocal%/... on Windows,
// ~/.local/share/... on unix). This will place the folder in a location we can trust
// to be able to get back to consistently as long as we're working with the same
// solution and the same workspace kind.
var appDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.Create);
return Path.Combine(appDataFolder, "Microsoft", "VisualStudio", "Roslyn", "Cache");
}
public string? TryGetStorageLocation(Solution solution)
{
if (!IsSupported(solution.Workspace))
......@@ -40,15 +50,11 @@ public DefaultPersistentStorageLocationService()
// Ensure that each unique workspace kind for any given solution has a unique
// folder to store their data in.
// Store in the LocalApplicationData/Roslyn/hash folder (%appdatalocal%/... on Windows,
// ~/.local/share/... on unix). This will place the folder in a location we can trust
// to be able to get back to consistently as long as we're working with the same
// solution and the same workspace kind.
var appDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.Create);
var cacheDirectory = GetCacheDirectory();
var kind = StripInvalidPathChars(solution.Workspace.Kind ?? "");
var hash = StripInvalidPathChars(Checksum.Create(solution.FilePath).ToString());
return Path.Combine(appDataFolder, "Microsoft", "VisualStudio", "Roslyn", "Cache", kind, hash);
return Path.Combine(cacheDirectory, kind, hash);
static string StripInvalidPathChars(string val)
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册