From f099130519ee7bd598db5ab9b50e1b92989a5a10 Mon Sep 17 00:00:00 2001 From: Ruan Beukes Date: Wed, 15 Jun 2022 17:31:36 +0800 Subject: [PATCH 1/8] scan packages added by the developer and ignore sub-dependencies. --- .../Mocking.Helpers/Moq/MoqIsAnyCompletion.cs | 3 ++- .../NSubstituteArgAnyCompletion.cs | 3 ++- .../Mocking.Helpers/PackagesHelper.cs | 26 +++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 Mocking.Helpers/Mocking.Helpers/PackagesHelper.cs diff --git a/Mocking.Helpers/Mocking.Helpers/Moq/MoqIsAnyCompletion.cs b/Mocking.Helpers/Mocking.Helpers/Moq/MoqIsAnyCompletion.cs index dd26a50..41ae3da 100644 --- a/Mocking.Helpers/Mocking.Helpers/Moq/MoqIsAnyCompletion.cs +++ b/Mocking.Helpers/Mocking.Helpers/Moq/MoqIsAnyCompletion.cs @@ -26,7 +26,8 @@ public override async Task ProvideCompletionsAsync(CompletionContext context) { if (!context.Document.SupportsSemanticModel || !context.Document.SupportsSyntaxTree) return; - var hasMoqReferenced = context.Document.Project.MetadataReferences.Any(r => r.Display.Contains(this._provider.AssemblyName)); + var hasMoqReferenced = PackagesHelper.GetProjectNugetPackages(context.Document.Project).Any(x => x.Equals(this._provider.AssemblyName, StringComparison.InvariantCultureIgnoreCase)); + if (!hasMoqReferenced) return; var syntaxRoot = await context.Document.GetSyntaxRootAsync(); diff --git a/Mocking.Helpers/Mocking.Helpers/NSubstitute/NSubstituteArgAnyCompletion.cs b/Mocking.Helpers/Mocking.Helpers/NSubstitute/NSubstituteArgAnyCompletion.cs index ebde3b2..b9cecaf 100644 --- a/Mocking.Helpers/Mocking.Helpers/NSubstitute/NSubstituteArgAnyCompletion.cs +++ b/Mocking.Helpers/Mocking.Helpers/NSubstitute/NSubstituteArgAnyCompletion.cs @@ -26,7 +26,8 @@ public override async Task ProvideCompletionsAsync(CompletionContext context) { if (!context.Document.SupportsSemanticModel || !context.Document.SupportsSyntaxTree) return; - var hasNSubstituteReferenced = context.Document.Project.MetadataReferences.Any(r => r.Display.Contains(this._provider.AssemblyName)); + var hasNSubstituteReferenced = PackagesHelper.GetProjectNugetPackages(context.Document.Project).Any(x => x.Equals(this._provider.AssemblyName, StringComparison.InvariantCultureIgnoreCase)); + if (!hasNSubstituteReferenced) return; var syntaxRoot = await context.Document.GetSyntaxRootAsync(); diff --git a/Mocking.Helpers/Mocking.Helpers/PackagesHelper.cs b/Mocking.Helpers/Mocking.Helpers/PackagesHelper.cs new file mode 100644 index 0000000..268fd1e --- /dev/null +++ b/Mocking.Helpers/Mocking.Helpers/PackagesHelper.cs @@ -0,0 +1,26 @@ +using Microsoft.CodeAnalysis; +using System; +using System.Collections.Generic; +using System.Xml; + +namespace Mocking.Helpers +{ + public static class PackagesHelper + { + // btw, feel free to refactor, just a quick test + public static IEnumerable GetProjectNugetPackages(Project project) + { + var nugetPackages = new List(); + var csproj = new XmlDocument(); + csproj.Load(project.FilePath); + var nodes = csproj.SelectNodes("//PackageReference[@Include and @Version]"); + foreach (XmlNode packageReference in nodes) + { + var packageName = packageReference.Attributes["Include"].Value; + nugetPackages.Add(packageName); + } + + return nugetPackages; + } + } +} From 26a1da6e000b5a7d0a316e1440705f49126c6cc8 Mon Sep 17 00:00:00 2001 From: Ruan Beukes Date: Wed, 15 Jun 2022 20:55:37 +0800 Subject: [PATCH 2/8] add build pipeline --- .github/workflows/CI_main.yml | 58 +++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 .github/workflows/CI_main.yml diff --git a/.github/workflows/CI_main.yml b/.github/workflows/CI_main.yml new file mode 100644 index 0000000..592aaa6 --- /dev/null +++ b/.github/workflows/CI_main.yml @@ -0,0 +1,58 @@ +name: CI-master + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +jobs: + build: + name: build + runs-on: windows-latest + steps: + - name: checkout code + uses: actions/checkout@v3 + + - name: get Version from source.extension.vsixmanifest, and append version with run_number + run: | + $manifestPath = '${{ github.workspace }}\Mocking.Helpers\Mocking.Helpers.Vsix\source.extension.vsixmanifest' + $manifestXml = [xml](Get-Content $manifestPath -Raw) + $version = $manifestXml.PackageManifest.Metadata.Identity.Version + $split = $version.Split('.') + $version = $split[0] + '.' + $split[1] + '.' + $split[2] + '.' + ${{ github.run_number }} + echo "APP_VERSION=$version" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append + $manifestXml.PackageManifest.Metadata.Identity.Version = $version + $manifestXml.save($manifestPath) + + - name: Print content of source.extension.vsixmanifest + run: get-content .\Mocking.Helpers\Mocking.Helpers.Vsix\source.extension.vsixmanifest + + - name: print APP_VERSION + run: Write-Host $APP_VERSION + + - name: add msbuild to PATH + uses: microsoft/setup-msbuild@v1.1 + + - name: setup nuget + uses: nuget/setup-nuget@v1 + with: + nuget-version: '6.x' + + - name: nuget restore + run: nuget restore Mocking.Helpers.sln + + - name: build solution + run: msbuild Mocking.Helpers.sln -t:rebuild -property:Configuration=Release + + - name: rename Mocking.Helpers.vsix to Mocking.Helpers.W.X.Y.Z.vsix + run: ren ${{ github.workspace }}\Mocking.Helpers\Mocking.Helpers.Vsix\bin\Release\net472\Mocking.Helpers.vsix Mocking.Helpers.${{ env.APP_VERSION }}.vsix + + - name: create artifact + uses: actions/upload-artifact@v3 + with: + name: Mocking.Helpers.${{ env.APP_VERSION }}.vsix + path: ${{ github.workspace }}\Mocking.Helpers\Mocking.Helpers.Vsix\bin\Release\net472\Mocking.Helpers.${{ env.APP_VERSION }}.vsix From e3c4c04e2b4d6436873a7ced56feaa242b42235e Mon Sep 17 00:00:00 2001 From: Ruan Beukes Date: Wed, 15 Jun 2022 21:05:08 +0800 Subject: [PATCH 3/8] could this fix the build? --- .../Mocking.Helpers.Vsix/source.extension.vsixmanifest | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Mocking.Helpers/Mocking.Helpers.Vsix/source.extension.vsixmanifest b/Mocking.Helpers/Mocking.Helpers.Vsix/source.extension.vsixmanifest index e6aaeb6..6b3e066 100644 --- a/Mocking.Helpers/Mocking.Helpers.Vsix/source.extension.vsixmanifest +++ b/Mocking.Helpers/Mocking.Helpers.Vsix/source.extension.vsixmanifest @@ -21,7 +21,7 @@ amd64 - + x86 From 40214f2d3d0e6db9ffbadf647d09b4fd699443ae Mon Sep 17 00:00:00 2001 From: Ruan Beukes Date: Wed, 15 Jun 2022 21:22:20 +0800 Subject: [PATCH 4/8] bump the .Net V4.8 (just a test to see if build works) --- .../Mocking.Helpers.Vsix/Mocking.Helpers.Vsix.csproj | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Mocking.Helpers/Mocking.Helpers.Vsix/Mocking.Helpers.Vsix.csproj b/Mocking.Helpers/Mocking.Helpers.Vsix/Mocking.Helpers.Vsix.csproj index 133e6c5..16fc21e 100644 --- a/Mocking.Helpers/Mocking.Helpers.Vsix/Mocking.Helpers.Vsix.csproj +++ b/Mocking.Helpers/Mocking.Helpers.Vsix/Mocking.Helpers.Vsix.csproj @@ -12,6 +12,7 @@ + @@ -25,7 +26,7 @@ Properties Mocking.Helpers.Vsix Mocking.Helpers - v4.6.1 + v4.8 false false false From 9a454004e99c5d11230b8a250936b6f5bdb9c26a Mon Sep 17 00:00:00 2001 From: Ruan Beukes Date: Wed, 15 Jun 2022 21:32:08 +0800 Subject: [PATCH 5/8] fix path --- .github/workflows/CI_main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CI_main.yml b/.github/workflows/CI_main.yml index 592aaa6..213ddb3 100644 --- a/.github/workflows/CI_main.yml +++ b/.github/workflows/CI_main.yml @@ -49,10 +49,10 @@ jobs: run: msbuild Mocking.Helpers.sln -t:rebuild -property:Configuration=Release - name: rename Mocking.Helpers.vsix to Mocking.Helpers.W.X.Y.Z.vsix - run: ren ${{ github.workspace }}\Mocking.Helpers\Mocking.Helpers.Vsix\bin\Release\net472\Mocking.Helpers.vsix Mocking.Helpers.${{ env.APP_VERSION }}.vsix + run: ren ${{ github.workspace }}\Mocking.Helpers\Mocking.Helpers.vsix\bin\Release\Mocking.Helpers.vsix Mocking.Helpers.${{ env.APP_VERSION }}.vsix - name: create artifact uses: actions/upload-artifact@v3 with: name: Mocking.Helpers.${{ env.APP_VERSION }}.vsix - path: ${{ github.workspace }}\Mocking.Helpers\Mocking.Helpers.Vsix\bin\Release\net472\Mocking.Helpers.${{ env.APP_VERSION }}.vsix + path: ${{ github.workspace }}\Mocking.Helpers\Mocking.Helpers.vsix\bin\Release\Mocking.Helpers.${{ env.APP_VERSION }}.vsix From 971e1a53cf5b8323e8eda73b195e82bb714213b5 Mon Sep 17 00:00:00 2001 From: Ruan Beukes Date: Wed, 15 Jun 2022 21:41:44 +0800 Subject: [PATCH 6/8] minor - remove comment [skip ci] --- Mocking.Helpers/Mocking.Helpers/PackagesHelper.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Mocking.Helpers/Mocking.Helpers/PackagesHelper.cs b/Mocking.Helpers/Mocking.Helpers/PackagesHelper.cs index 268fd1e..2b4f327 100644 --- a/Mocking.Helpers/Mocking.Helpers/PackagesHelper.cs +++ b/Mocking.Helpers/Mocking.Helpers/PackagesHelper.cs @@ -7,7 +7,6 @@ namespace Mocking.Helpers { public static class PackagesHelper { - // btw, feel free to refactor, just a quick test public static IEnumerable GetProjectNugetPackages(Project project) { var nugetPackages = new List(); From 41d9a429e56e12d62001cf89da8774d8dde70c8f Mon Sep 17 00:00:00 2001 From: Ruan Beukes Date: Thu, 16 Jun 2022 19:14:19 +0800 Subject: [PATCH 7/8] check FakeItEasy installed package --- .../Mocking.Helpers/FakeItEasy/FakeItEasyIgnoredCompletion.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Mocking.Helpers/Mocking.Helpers/FakeItEasy/FakeItEasyIgnoredCompletion.cs b/Mocking.Helpers/Mocking.Helpers/FakeItEasy/FakeItEasyIgnoredCompletion.cs index 4076f44..a7e9f3f 100644 --- a/Mocking.Helpers/Mocking.Helpers/FakeItEasy/FakeItEasyIgnoredCompletion.cs +++ b/Mocking.Helpers/Mocking.Helpers/FakeItEasy/FakeItEasyIgnoredCompletion.cs @@ -30,7 +30,7 @@ public override async Task ProvideCompletionsAsync(CompletionContext context) { if (!context.Document.SupportsSemanticModel || !context.Document.SupportsSyntaxTree) return; - var hasFakeItEasyReferenced = context.Document.Project.MetadataReferences.Any(r => r.Display.Contains(this._provider.AssemblyName)); + var hasFakeItEasyReferenced = PackagesHelper.GetProjectNugetPackages(context.Document.Project).Any(x => x.Equals(this._provider.AssemblyName, StringComparison.InvariantCultureIgnoreCase)); if (!hasFakeItEasyReferenced) return; var syntaxRoot = await context.Document.GetSyntaxRootAsync(); From 3d89f602f423f6568da1a9a01335db02aa810001 Mon Sep 17 00:00:00 2001 From: Ruan Beukes Date: Thu, 16 Jun 2022 19:39:55 +0800 Subject: [PATCH 8/8] use Linq to ge nuget packes --- Mocking.Helpers/Mocking.Helpers/PackagesHelper.cs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Mocking.Helpers/Mocking.Helpers/PackagesHelper.cs b/Mocking.Helpers/Mocking.Helpers/PackagesHelper.cs index 2b4f327..b29e76b 100644 --- a/Mocking.Helpers/Mocking.Helpers/PackagesHelper.cs +++ b/Mocking.Helpers/Mocking.Helpers/PackagesHelper.cs @@ -1,6 +1,7 @@ using Microsoft.CodeAnalysis; using System; using System.Collections.Generic; +using System.Linq; using System.Xml; namespace Mocking.Helpers @@ -9,15 +10,13 @@ public static class PackagesHelper { public static IEnumerable GetProjectNugetPackages(Project project) { - var nugetPackages = new List(); var csproj = new XmlDocument(); csproj.Load(project.FilePath); - var nodes = csproj.SelectNodes("//PackageReference[@Include and @Version]"); - foreach (XmlNode packageReference in nodes) - { - var packageName = packageReference.Attributes["Include"].Value; - nugetPackages.Add(packageName); - } + + var nugetPackages = csproj.SelectNodes("//PackageReference[@Include and @Version]") + .OfType() + .Select(x => x.Attributes["Include"].Value) + .ToList(); return nugetPackages; }