我在Visual Studio解决方案中有一些项目,它们的项目引用包含被引用项目的错误GUID。(可能是由于在某个阶段重新创建了引用的项目)
例如:考虑一个具有以下属性的项目CoreProject.csproj:
<ProjectGuid>{93803F9C-8C65-4949-8D44-AB7A3D0452C8}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>CoreProject</RootNamespace>
<AssemblyName>CoreProject</AssemblyName>另一个项目包括对此的引用,但在某些阶段,GUID已更改,现在是不正确的。
<ProjectReference Include="..\CoreProject\CoreProject.csproj">
<Project>{5FD52517-79F8-41D2-B6F2-EA2D8A886549}</Project>
<Name>CoreProject</Name>
</ProjectReference>解决方案仍然可以在Visual Studio和msbuild中正确加载和构建,但我怀疑在VS中使用错误的GUID可能会对性能产生一些影响。
这个解决方案很大,有很多项目都有这个问题,我不希望手动重新添加这些引用。有没有什么工具或宏可以“修复”项目引用GUID?
发布于 2012-05-31 04:05:23
我认为一个基本的控制台应用程序应该可以做到这一点,就像这样:
using System;
using System.IO;
using System.Linq;
using Microsoft.Build.Evaluation;
public class Program
{
public static void Main(String[] args)
{
var projects = Directory.EnumerateFiles(@"...", "*.csproj", SearchOption.AllDirectories)
.Select(x =>
{
try
{
return new Project(x);
}
catch
{
return null;
}
})
.Where(x => x != null)
.ToList();
var guids = projects.ToDictionary(p => p.FullPath, p => p.GetPropertyValue("ProjectGuid"));
foreach (var project in projects)
{
var save = false;
foreach (var reference in project.GetItems("ProjectReference"))
{
var path = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(project.FullPath), reference.EvaluatedInclude));
if (!guids.ContainsKey(path))
{
Console.WriteLine("No {0}", Path.GetFileName(path));
continue;
}
var guid = guids[path];
var meta = reference.GetMetadataValue("Project");
if (meta != guid)
{
Console.WriteLine("{0} -> {1}", meta, guid);
reference.SetMetadataValue("Project", guid);
save = true;
}
}
if (save)
project.Save(project.FullPath);
}
}
}https://stackoverflow.com/questions/10817857
复制相似问题