Intent.Modules icon indicating copy to clipboard operation
Intent.Modules copied to clipboard

NuGet Installer - Handle version strings more gracefully

Open JonathanLydall opened this issue 6 years ago • 0 comments

The NuGet installer chokes on the following .csproj file while VS 2019 doesn't mind.

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <TargetFramework>netstandard2.0</TargetFramework>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="Ardalis.GuardClauses" Version="1.2.8" />
        <PackageReference Include="Autofac" Version="4.8.1" />
        <PackageReference Include="Microsoft.Azure.DocumentDB.Core" Version="2.5.1" />
        <PackageReference Include="Microsoft.CSharp" Version="4.5.0" />
        <PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="1.0.2.0" />
        <PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="2.2.4" />
        <PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="2.2.0.0" />
        <PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="2.2.0.0" />
        <PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="2.2.0.0" />
        <PackageReference Include="Microsoft.Extensions.Options" Version="2.2.0.0" />
        <PackageReference Include="NServiceBus.Autofac" Version="7.0.0" />
        <PackageReference Include="NServiceBus.UniformSession" Version="2.1.0" />
        <PackageReference Include="Serilog" Version="2.8.0" />
    </ItemGroup>

</Project>

The error thrown is:

System.ArgumentException: '1.0.2.0' is not a valid version string.
Parameter name: value
   at NuGet.Versioning.SemanticVersion.Parse(String value)
   at Intent.Modules.VisualStudio.Projects.NuGet.HelperTypes.NuGetPackage.Create(String version, IEnumerable`1 includeAssets, IEnumerable`1 privateAssets) in C:\Dev\Intent.Modules\Modules\Intent.Modules.VisualStudio.Projects\NuGet\HelperTypes\NuGetPackage.cs:line 25
   at Intent.Modules.VisualStudio.Projects.NuGet.SchemeProcessors.LeanSchemeProcessor.<>c.<GetInstalledPackages>b__0_1(XElement element) in C:\Dev\Intent.Modules\Modules\Intent.Modules.VisualStudio.Projects\NuGet\SchemeProcessors\LeanSchemeProcessor.cs:line 38
   at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
   at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector)
   at Intent.Modules.VisualStudio.Projects.NuGet.SchemeProcessors.LeanSchemeProcessor.GetInstalledPackages(IProject project, XNode xNode) in C:\Dev\Intent.Modules\Modules\Intent.Modules.VisualStudio.Projects\NuGet\SchemeProcessors\LeanSchemeProcessor.cs:line 18
   at Intent.Modules.VisualStudio.Projects.NuGet.NugetInstallerFactoryExtension.DeterminePackages(IEnumerable`1 applicationProjects, Func`2 loadDelegate) in C:\Dev\Intent.Modules\Modules\Intent.Modules.VisualStudio.Projects\NuGet\NugetInstallerFactoryExtension.cs:line 198
   at Intent.Modules.VisualStudio.Projects.NuGet.NugetInstallerFactoryExtension.Execute(IEnumerable`1 applicationProjects, ITracing tracing, Action`2 saveProjectDelegate, Func`2 loadProjectDelegate) in C:\Dev\Intent.Modules\Modules\Intent.Modules.VisualStudio.Projects\NuGet\NugetInstallerFactoryExtension.cs:line 133
   at Intent.Modules.VisualStudio.Projects.NuGet.NugetInstallerFactoryExtension.OnStep(IApplication application, String step) in C:\Dev\Intent.Modules\Modules\Intent.Modules.VisualStudio.Projects\NuGet\NugetInstallerFactoryExtension.cs:line 79
   at Intent.SoftwareFactory.ProcessOrchestration.<>c__DisplayClass17_0.<Process>b__9(IExecutionLifeCycle fe) in C:\Dev\Intent\Intent.IntentArchitect\IntentArchitect.SoftwareFactory\Intent.SoftwareFactory\ProcessOrchestration.cs:line 182
   at Intent.SoftwareFactory.FactoryExtensionHelper.ExtensionPoint[TImplements](String descritpion, Action`1 action) in C:\Dev\Intent\Intent.IntentArchitect\IntentArchitect.SoftwareFactory\Intent.SoftwareFactory\FactoryExtensionHelper.cs:line 29
   at Intent.SoftwareFactory.ProcessOrchestration.Process(String[] applicationIds) in C:\Dev\Intent\Intent.IntentArchitect\IntentArchitect.SoftwareFactory\Intent.SoftwareFactory\ProcessOrchestration.cs:line 182
   at Intent.SoftwareFactory.IntentManager.Run(String applicationIds) in C:\Dev\Intent\Intent.IntentArchitect\IntentArchitect.SoftwareFactory\Intent.SoftwareFactory\IntentManager.cs:line 240
   at Intent.SoftwareFactory.Factory.Run(ExecutionContext executionContext) in C:\Dev\Intent\Intent.IntentArchitect\IntentArchitect.SoftwareFactory\Intent.SoftwareFactory\Factory.cs:line 97

I suspect this file was hand-crafted, but we could handle it anyway by doing a check to see if it can parse as a normal System.Version, and then if its revision is 0, then alter the string to drop the trailing .0.

JonathanLydall avatar Aug 20 '19 20:08 JonathanLydall