Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: projects in sln build twice #8386

Merged
merged 1 commit into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace Microsoft.DocAsCode.Metadata.ManagedReference
using System.Text;
using System.Threading.Tasks;

using Microsoft.Build.Construction;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.MSBuild;

Expand Down Expand Up @@ -142,24 +143,19 @@ private async Task SaveAllMembersFromCacheAsync()
using (new LoggerFileScope(path))
{
documentCache.AddDocument(path, path);
var solution = await GetSolutionAsync(path);
if (solution != null)
foreach (var project in SolutionFile.Parse(path).ProjectsInOrder)
{
foreach (var project in solution.Projects)
{
var projectFile = new FileInformation(project.FilePath);
if (project.ProjectType is not SolutionProjectType.KnownToBeMSBuildFormat)
continue;

// If the project is supported, add to project dictionary, otherwise, ignore
if (projectFile.Type == FileType.Project)
{
projectCache.GetOrAdd(projectFile.NormalizedPath,
s => LoadProject(projectFile.NormalizedPath));
}
else
{
Logger.LogWarning($"Project {projectFile.RawPath} inside solution {path} is ignored, supported projects are csproj, fsproj and vbproj.");
}
var projectFile = new FileInformation(project.AbsolutePath);
if (projectFile.Type is not FileType.Project)
{
Logger.LogWarning($"Skip unsupported project {project.AbsolutePath}.");
continue;
}

projectCache.GetOrAdd(projectFile.NormalizedPath, LoadProject);
}
}
}
Expand Down Expand Up @@ -749,23 +745,6 @@ private static Dictionary<string, ReferenceItem> MergeYamlProjectReferences(List
return result;
}

private async Task<Solution> GetSolutionAsync(string path)
{
try
{
Logger.LogVerbose("Loading solution...");
var solution = await _workspace.OpenSolutionAsync(path);
_workspace.CloseSolution();
Logger.LogVerbose($"Solution {solution.FilePath} loaded.");
return solution;
}
catch (Exception e)
{
Logger.Log(LogLevel.Warning, $"Error opening solution {path}: {e.Message}. Ignored.");
return null;
}
}

private Project GetProject(ConcurrentDictionary<string, Project> cache, string path)
{
return cache.GetOrAdd(path.ToNormalizedFullPath(), s =>
Expand Down
1 change: 0 additions & 1 deletion src/Microsoft.DocAsCode.Dotnet/FileInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ private static FileType GetFileType(string filePath)
case ".sln":
return FileType.Solution;
case ".csproj":
case ".fsproj":
yufeih marked this conversation as resolved.
Show resolved Hide resolved
case ".vbproj":
return FileType.Project;
case ".cs":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<ItemGroup>
<PackageReference Include="ICSharpCode.Decompiler" Version="8.0.0.7246-preview3" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="7.0.0" />
<PackageReference Include="Microsoft.Build" Version="17.4.0" ExcludeAssets="runtime" />
yufeih marked this conversation as resolved.
Show resolved Hide resolved
<PackageReference Include="Microsoft.Build.Locator" Version="1.5.5" />
<PackageReference Include="Microsoft.CodeAnalysis" Version="4.4.0" />
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.4.0" />
Expand Down