Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

Commit 8926d8b

Browse files
adalonkzu
authored andcommitted
Avoiding to show a warning when a project reference to a legacy .csproj is added
And also enabling NuProj -> NuProj project references
1 parent 37fef7e commit 8926d8b

1 file changed

Lines changed: 39 additions & 93 deletions

File tree

Lines changed: 39 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,39 @@
1-
//using System;
2-
//using System.ComponentModel.Composition;
3-
//using System.Diagnostics.CodeAnalysis;
4-
//using System.Threading.Tasks;
5-
6-
//using System.Collections.Immutable;
7-
//using Microsoft.VisualStudio.ProjectSystem;
8-
//using Microsoft.VisualStudio.ProjectSystem.References;
9-
//using Microsoft.VisualStudio.Shell.Interop;
10-
11-
//namespace NuGet.Packaging.VisualStudio
12-
//{
13-
// [Export(typeof(IValidProjectReferenceChecker))]
14-
// [Order(1000)]
15-
// [AppliesTo(NuProjCapabilities.NuProj)]
16-
// public class NuProjValidProjectReferenceChecker : IValidProjectReferenceChecker
17-
// {
18-
// // This import must be present so that this part applies to a specific project.
19-
// [Import]
20-
// [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]
21-
// public UnconfiguredProject UnconfiguredProject { get; set; }
22-
23-
// public Task<SupportedCheckResult> CanAddProjectReferenceAsync(object referencedProject)
24-
// {
25-
// var result = CanAddProjectReference(referencedProject);
26-
// return Task.FromResult(result);
27-
// }
28-
29-
// public Task<CanAddProjectReferencesResult> CanAddProjectReferencesAsync(IImmutableSet<object> referencedProjects)
30-
// {
31-
// if (referencedProjects == null)
32-
// throw new ArgumentNullException("referencedProjects");
33-
34-
// var results = ImmutableDictionary<object, SupportedCheckResult>.Empty;
35-
36-
// foreach (object referencedProject in referencedProjects)
37-
// {
38-
// var result = CanAddProjectReference(referencedProject);
39-
// results = results.Add(referencedProject, result);
40-
// }
41-
42-
// return Task.FromResult(new CanAddProjectReferencesResult(results, null));
43-
// }
44-
45-
// public Task<SupportedCheckResult> CanBeReferencedAsync(object referencingProject)
46-
// {
47-
// return Task.FromResult(SupportedCheckResult.NotSupported);
48-
// }
49-
50-
// private static SupportedCheckResult CanAddProjectReference(object referencedProject)
51-
// {
52-
// return CanReference(referencedProject)
53-
// ? SupportedCheckResult.Supported
54-
// : SupportedCheckResult.Unknown;
55-
// }
56-
57-
// private static bool CanReference(object referencedProject)
58-
// {
59-
// var r = referencedProject as IVsProjectReference;
60-
// return r != null &&
61-
// CanReference(r.FullPath);
62-
// }
63-
64-
// private static bool CanReference(string path)
65-
// {
66-
// return IsNuProj(path) ||
67-
// HasGetNuGetOutputAndTargetFrameworkInformationTarget(path);
68-
// }
69-
70-
// private static bool IsNuProj(string path)
71-
// {
72-
// return HasExtension(path, "." + Constants.ProjectExtension);
73-
// }
74-
75-
// private static bool HasGetNuGetOutputAndTargetFrameworkInformationTarget(string path)
76-
// {
77-
// // Here we are cheating like no tomorrow. Ideally, we'd actually inspect in the project file and check
78-
// // whether it actually has an MSBuild target named "GetNuGetOutputAndTargetFrameworkInformation".
79-
// //
80-
// // For now we'll just whitelist the known project files C#, VB and F#.
81-
// return HasExtension(path, ".csproj") ||
82-
// HasExtension(path, ".vbproj") ||
83-
// HasExtension(path, ".fsproj");
84-
// }
85-
86-
// private static bool HasExtension(string path, string extension)
87-
// {
88-
// return path != null &&
89-
// extension != null &&
90-
// path.EndsWith(extension, StringComparison.OrdinalIgnoreCase);
91-
// }
92-
// }
93-
//}
1+
using System;
2+
using System.ComponentModel.Composition;
3+
using System.Diagnostics.CodeAnalysis;
4+
using System.Threading.Tasks;
5+
using System.Linq;
6+
using System.Collections.Immutable;
7+
using Microsoft.VisualStudio.ProjectSystem;
8+
using Microsoft.VisualStudio.ProjectSystem.References;
9+
using System.Collections.Generic;
10+
11+
namespace NuGet.Packaging.VisualStudio
12+
{
13+
[Export(typeof(IValidProjectReferenceChecker))]
14+
[Order(1000)]
15+
[AppliesTo(NuProjCapabilities.NuProj)]
16+
public class NuProjValidProjectReferenceChecker : IValidProjectReferenceChecker
17+
{
18+
// This import must be present so that this part applies to a specific project.
19+
[Import]
20+
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]
21+
public UnconfiguredProject UnconfiguredProject { get; set; }
22+
23+
public Task<SupportedCheckResult> CanAddProjectReferenceAsync(object referencedProject) =>
24+
Task.FromResult(CanAddProjectReference(referencedProject));
25+
26+
public Task<CanAddProjectReferencesResult> CanAddProjectReferencesAsync(IImmutableSet<object> referencedProjects) =>
27+
Task.FromResult(
28+
new CanAddProjectReferencesResult(
29+
ImmutableDictionary<object, SupportedCheckResult>.Empty.AddRange(
30+
referencedProjects.Select(x =>
31+
new KeyValuePair<object, SupportedCheckResult>(x, CanAddProjectReference(x)))
32+
), null));
33+
34+
public Task<SupportedCheckResult> CanBeReferencedAsync(object referencingProject) =>
35+
Task.FromResult(SupportedCheckResult.Supported);
36+
37+
SupportedCheckResult CanAddProjectReference(object referencedProject) => SupportedCheckResult.Supported;
38+
}
39+
}

0 commit comments

Comments
 (0)