diff options
author | Tom Meschter <tom.meschter@valinor.org> | 2017-03-20 22:41:43 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-20 22:41:43 +0300 |
commit | 7df3f2b3354c1783e9535d46072443866f39cab1 (patch) | |
tree | 92d89f080e9677fb853c6fc60aa9be6634c1fe49 | |
parent | 42b97d978be258bbf915e56bb69747bc8956a3af (diff) | |
parent | dadda09b824f959dc21557a22645c1500faf9d45 (diff) |
Merge pull request #33 from tmeschter/DontShowProjectsAsPackages
Don't show project references as package references in Solution Explorer
7 files changed, 303 insertions, 8 deletions
diff --git a/src/Microsoft.NuGet.Build.Tasks.Tests/Json/Json.Designer.cs b/src/Microsoft.NuGet.Build.Tasks.Tests/Json/Json.Designer.cs index eeed7e7..f0345cb 100644 --- a/src/Microsoft.NuGet.Build.Tasks.Tests/Json/Json.Designer.cs +++ b/src/Microsoft.NuGet.Build.Tasks.Tests/Json/Json.Designer.cs @@ -233,6 +233,35 @@ namespace Microsoft.NuGet.Build.Tasks.Tests.Json { /// <summary> /// Looks up a localized string similar to { + /// "version": 2, + /// "targets": { + /// ".NETFramework,Version=v4.5.2": { + /// "log4net/2.0.7": { + /// "type": "package", + /// "compile": { + /// "lib/net45-full/log4net.dll": {} + /// }, + /// "runtime": { + /// "lib/net45-full/log4net.dll": {} + /// } + /// }, + /// "Newtonsoft.Json/9.0.1": { + /// "type": "package", + /// "compile": { + /// "lib/net45/Newtonsoft.Json.dll": {} + /// }, + /// "runtime": { + /// "lib/net45/Newtonsoft.Json.dll": {} + /// [rest of string was truncated]";. + /// </summary> + internal static string ProjectDependency { + get { + return ResourceManager.GetString("ProjectDependency", resourceCulture); + } + } + + /// <summary> + /// Looks up a localized string similar to { /// "locked": false, /// "version": -9996, /// "targets": { diff --git a/src/Microsoft.NuGet.Build.Tasks.Tests/Json/Json.resx b/src/Microsoft.NuGet.Build.Tasks.Tests/Json/Json.resx index e2273cf..a59102f 100644 --- a/src/Microsoft.NuGet.Build.Tasks.Tests/Json/Json.resx +++ b/src/Microsoft.NuGet.Build.Tasks.Tests/Json/Json.resx @@ -145,4 +145,7 @@ <data name="MultipleProjectFileDependencyGroups" type="System.Resources.ResXFileRef, System.Windows.Forms"> <value>multipleprojectfiledependencygroups.json;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value> </data> + <data name="ProjectDependency" type="System.Resources.ResXFileRef, System.Windows.Forms"> + <value>ProjectDependency.assets.json;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value> + </data> </root>
\ No newline at end of file diff --git a/src/Microsoft.NuGet.Build.Tasks.Tests/Json/ProjectDependency.assets.json b/src/Microsoft.NuGet.Build.Tasks.Tests/Json/ProjectDependency.assets.json new file mode 100644 index 0000000..c718a5a --- /dev/null +++ b/src/Microsoft.NuGet.Build.Tasks.Tests/Json/ProjectDependency.assets.json @@ -0,0 +1,213 @@ +{ + "version": 2, + "targets": { + ".NETFramework,Version=v4.5.2": { + "log4net/2.0.7": { + "type": "package", + "compile": { + "lib/net45-full/log4net.dll": {} + }, + "runtime": { + "lib/net45-full/log4net.dll": {} + } + }, + "Newtonsoft.Json/9.0.1": { + "type": "package", + "compile": { + "lib/net45/Newtonsoft.Json.dll": {} + }, + "runtime": { + "lib/net45/Newtonsoft.Json.dll": {} + } + }, + "ClassLibrary1/1.0.0": { + "type": "project" + } + }, + ".NETFramework,Version=v4.5.2/win": { + "log4net/2.0.7": { + "type": "package", + "compile": { + "lib/net45-full/log4net.dll": {} + }, + "runtime": { + "lib/net45-full/log4net.dll": {} + } + }, + "Newtonsoft.Json/9.0.1": { + "type": "package", + "compile": { + "lib/net45/Newtonsoft.Json.dll": {} + }, + "runtime": { + "lib/net45/Newtonsoft.Json.dll": {} + } + }, + "ClassLibrary1/1.0.0": { + "type": "project" + } + }, + ".NETFramework,Version=v4.5.2/win-x64": { + "log4net/2.0.7": { + "type": "package", + "compile": { + "lib/net45-full/log4net.dll": {} + }, + "runtime": { + "lib/net45-full/log4net.dll": {} + } + }, + "Newtonsoft.Json/9.0.1": { + "type": "package", + "compile": { + "lib/net45/Newtonsoft.Json.dll": {} + }, + "runtime": { + "lib/net45/Newtonsoft.Json.dll": {} + } + }, + "ClassLibrary1/1.0.0": { + "type": "project" + } + }, + ".NETFramework,Version=v4.5.2/win-x86": { + "log4net/2.0.7": { + "type": "package", + "compile": { + "lib/net45-full/log4net.dll": {} + }, + "runtime": { + "lib/net45-full/log4net.dll": {} + } + }, + "Newtonsoft.Json/9.0.1": { + "type": "package", + "compile": { + "lib/net45/Newtonsoft.Json.dll": {} + }, + "runtime": { + "lib/net45/Newtonsoft.Json.dll": {} + } + }, + "ClassLibrary1/1.0.0": { + "type": "project" + } + } + }, + "libraries": { + "log4net/2.0.7": { + "sha512": "9zY5lPFy4ppjeaTKwHjXbHe6lhle64Bnwui3YDEnnlo4NzHcUE9/h4BqCn3PCCvYbpwO4+ceWdqk9J/lxrQ9dQ==", + "type": "package", + "path": "log4net/2.0.7", + "files": [ + "lib/net20-full/log4net.dll", + "lib/net20-full/log4net.xml", + "lib/net35-client/log4net.dll", + "lib/net35-client/log4net.xml", + "lib/net35-full/log4net.dll", + "lib/net35-full/log4net.xml", + "lib/net40-client/log4net.dll", + "lib/net40-client/log4net.xml", + "lib/net40-full/log4net.dll", + "lib/net40-full/log4net.xml", + "lib/net45-full/log4net.dll", + "lib/net45-full/log4net.xml", + "lib/netstandard1.3/log4net.dll", + "log4net.2.0.7.nupkg.sha512", + "log4net.nuspec" + ] + }, + "Newtonsoft.Json/9.0.1": { + "sha512": "U82mHQSKaIk+lpSVCbWYKNavmNH1i5xrExDEquU1i6I5pV6UMOqRnJRSlKO3cMPfcpp0RgDY+8jUXHdQ4IfXvw==", + "type": "package", + "path": "newtonsoft.json/9.0.1", + "files": [ + "lib/net20/Newtonsoft.Json.dll", + "lib/net20/Newtonsoft.Json.xml", + "lib/net35/Newtonsoft.Json.dll", + "lib/net35/Newtonsoft.Json.xml", + "lib/net40/Newtonsoft.Json.dll", + "lib/net40/Newtonsoft.Json.xml", + "lib/net45/Newtonsoft.Json.dll", + "lib/net45/Newtonsoft.Json.xml", + "lib/netstandard1.0/Newtonsoft.Json.dll", + "lib/netstandard1.0/Newtonsoft.Json.xml", + "lib/portable-net40+sl5+wp80+win8+wpa81/Newtonsoft.Json.dll", + "lib/portable-net40+sl5+wp80+win8+wpa81/Newtonsoft.Json.xml", + "lib/portable-net45+wp80+win8+wpa81/Newtonsoft.Json.dll", + "lib/portable-net45+wp80+win8+wpa81/Newtonsoft.Json.xml", + "newtonsoft.json.9.0.1.nupkg.sha512", + "newtonsoft.json.nuspec", + "tools/install.ps1" + ] + }, + "ClassLibrary1/1.0.0": { + "type": "project", + "path": "../ClassLibrary1/ClassLibrary1.csproj", + "msbuildProject": "../ClassLibrary1/ClassLibrary1.csproj" + } + }, + "projectFileDependencyGroups": { + ".NETFramework,Version=v4.5.2": [ + "ClassLibrary1 >= 1.0.0", + "Newtonsoft.Json >= 9.0.1", + "log4net >= 2.0.7" + ] + }, + "packageFolders": { + "C:\\Users\\tomescht\\.nuget\\packages\\": {} + }, + "project": { + "version": "1.0.0", + "restore": { + "projectUniqueName": "C:\\Users\\tomescht\\Documents\\Visual Studio 2017\\Projects\\WpfApp1\\WpfApp1\\WpfApp1.csproj", + "projectName": "WpfApp1", + "projectPath": "C:\\Users\\tomescht\\Documents\\Visual Studio 2017\\Projects\\WpfApp1\\WpfApp1\\WpfApp1.csproj", + "outputPath": "C:\\Users\\tomescht\\Documents\\Visual Studio 2017\\Projects\\WpfApp1\\WpfApp1\\obj\\", + "projectStyle": "PackageReference", + "originalTargetFrameworks": [ + "net452" + ], + "frameworks": { + "net452": { + "projectReferences": { + "C:\\Users\\tomescht\\Documents\\Visual Studio 2017\\Projects\\WpfApp1\\ClassLibrary1\\ClassLibrary1.csproj": { + "projectPath": "C:\\Users\\tomescht\\Documents\\Visual Studio 2017\\Projects\\WpfApp1\\ClassLibrary1\\ClassLibrary1.csproj" + } + } + } + } + }, + "dependencies": { + "Newtonsoft.Json": { + "target": "Package", + "version": "9.0.1" + }, + "log4net": { + "target": "Package", + "version": "[2.0.7, )" + } + }, + "frameworks": { + "net452": { + "dependencies": { + "Newtonsoft.Json": { + "target": "Package", + "version": "9.0.1" + } + } + } + }, + "runtimes": { + "win": { + "#import": [] + }, + "win-x64": { + "#import": [] + }, + "win-x86": { + "#import": [] + } + } + } +}
\ No newline at end of file diff --git a/src/Microsoft.NuGet.Build.Tasks.Tests/Microsoft.NuGet.Build.Tasks.Tests.csproj b/src/Microsoft.NuGet.Build.Tasks.Tests/Microsoft.NuGet.Build.Tasks.Tests.csproj index 2f0c78e..ccf4463 100644 --- a/src/Microsoft.NuGet.Build.Tasks.Tests/Microsoft.NuGet.Build.Tasks.Tests.csproj +++ b/src/Microsoft.NuGet.Build.Tasks.Tests/Microsoft.NuGet.Build.Tasks.Tests.csproj @@ -85,6 +85,7 @@ <None Include="Json\Win10.json" /> <None Include="Json\Win10.xunit.json" /> <None Include="project.json" /> + <None Include="Json\ProjectDependency.assets.json" /> <None Include="ProjectReferences\LockFileMissingMSBuildProjectThatProvidesAssets.json" /> <None Include="ProjectReferences\LockFileWithCSProjReference.json" /> </ItemGroup> diff --git a/src/Microsoft.NuGet.Build.Tasks.Tests/ReferenceResolutionTests.cs b/src/Microsoft.NuGet.Build.Tasks.Tests/ReferenceResolutionTests.cs index 828a72b..994fdb4 100644 --- a/src/Microsoft.NuGet.Build.Tasks.Tests/ReferenceResolutionTests.cs +++ b/src/Microsoft.NuGet.Build.Tasks.Tests/ReferenceResolutionTests.cs @@ -413,5 +413,16 @@ namespace Microsoft.NuGet.Build.Tasks.Tests Assert.Contains("FluentAssertions", packageNames); } + + [Fact] + public static void ProjectsNotIncludedInReferences() + { + var result = NuGetTestHelpers.ResolvePackagesWithJsonFileContents( + Json.Json.ProjectDependency, + targetMoniker: ".NETFramework,Version=v4.5.2", + runtimeIdentifier: "win"); + + Assert.DoesNotContain("ClassLibrary1", result.ReferencedPackages.Select(t => t.ItemSpec)); + } } } diff --git a/src/Microsoft.NuGet.Build.Tasks/Microsoft.NuGet.Build.Tasks.csproj b/src/Microsoft.NuGet.Build.Tasks/Microsoft.NuGet.Build.Tasks.csproj index 8aba143..3d8611b 100644 --- a/src/Microsoft.NuGet.Build.Tasks/Microsoft.NuGet.Build.Tasks.csproj +++ b/src/Microsoft.NuGet.Build.Tasks/Microsoft.NuGet.Build.Tasks.csproj @@ -80,4 +80,4 @@ <Target Name="AfterBuild"> </Target> --> -</Project> +</Project>
\ No newline at end of file diff --git a/src/Microsoft.NuGet.Build.Tasks/ResolveNuGetPackageAssets.cs b/src/Microsoft.NuGet.Build.Tasks/ResolveNuGetPackageAssets.cs index 3e12fb0..68ee462 100644 --- a/src/Microsoft.NuGet.Build.Tasks/ResolveNuGetPackageAssets.cs +++ b/src/Microsoft.NuGet.Build.Tasks/ResolveNuGetPackageAssets.cs @@ -854,24 +854,54 @@ namespace Microsoft.NuGet.Build.Tasks } var projectFileDependencyGroups = (JObject)lockFile["projectFileDependencyGroups"]; + var allPackageNames = GetAllPackageNames(lockFile); if (targetMoniker != null) { var targetSpecificDependencies = (JArray)projectFileDependencyGroups[targetMoniker]; if (targetSpecificDependencies != null) { - AddReferencedPackages(targetSpecificDependencies); + AddReferencedPackages(targetSpecificDependencies, allPackageNames); } } var universalDependencies = (JArray)projectFileDependencyGroups[""]; if (universalDependencies != null) { - AddReferencedPackages(universalDependencies); + AddReferencedPackages(universalDependencies, allPackageNames); } } - private void AddReferencedPackages(JArray packageDependencies) + /// <summary> + /// Returns the set of all the package names (not including version numbers) + /// in the "libraries" section of the assets/lock file. Note that this includes + /// only proper packages; projects are specifically excluded. + /// </summary> + private static SortedSet<string> GetAllPackageNames(JObject lockFile) + { + var allPackageNames = new SortedSet<string>(); + var libraries = (JObject)lockFile["libraries"]; + foreach (var library in libraries) + { + var libraryObject = (JObject)library.Value; + string type = (string)libraryObject["type"]; + if (type != null && + type.Equals("project", StringComparison.OrdinalIgnoreCase)) + { + continue; + } + + SplitPackageName(library.Key, out string name, out string version); + allPackageNames.Add(name); + } + + return allPackageNames; + } + + /// <summary> + /// Given a set of dependencies, identities the packages and adds their names to <see cref="_referencedPackages"/>. + /// </summary> + private void AddReferencedPackages(JArray packageDependencies, SortedSet<string> allPackageNames) { foreach (var packageDependency in packageDependencies.Select(v => (string)v)) { @@ -881,7 +911,10 @@ namespace Microsoft.NuGet.Build.Tasks ? packageDependency.Substring(0, firstSpace) : packageDependency; - _referencedPackages.Add(new TaskItem(packageName)); + if (allPackageNames.Contains(packageName)) + { + _referencedPackages.Add(new TaskItem(packageName)); + } } } @@ -906,9 +939,7 @@ namespace Microsoft.NuGet.Build.Tasks { foreach (var package in target) { - var nameParts = package.Key.Split('/'); - var id = nameParts[0]; - var version = nameParts[1]; + SplitPackageName(package.Key, out string id, out string version); var libraryObject = (JObject)lockFile["libraries"][package.Key]; @@ -933,6 +964,13 @@ namespace Microsoft.NuGet.Build.Tasks } } + private static void SplitPackageName(string key, out string id, out string version) + { + var nameParts = key.Split('/'); + id = nameParts[0]; + version = nameParts[1]; + } + private string GetAbsolutePathFromProjectRelativePath(string path) { return Path.GetFullPath(Path.Combine(Path.GetDirectoryName(Path.GetFullPath(ProjectLockFile)), path)); |