hvanbakel / CsprojToVs2017

Tooling for converting pre 2017 project to the new Visual Studio 2017 format.
MIT License
1.08k stars 120 forks source link

Nuspec <dependency/> without version gives null reference exception #273

Open jbuedel opened 4 years ago

jbuedel commented 4 years ago

We have a nuspec file that contains this:

<dependencies>
      <dependency id="dotnet4.7.1" />
      <dependency id="vfpoledb" version="1.0.0" />
      <dependency id="vcredist2017" />
    </dependencies>

The lack of version attributes seems to be causing a null ref exception.

~\Projects\AMS.Eclipse.Agent > dotnet migrate-2019 migrate
[11:06:17 INF] Reading package info from nuspec C:\Users\jbuedel\Projects\EclipsePro-Design\src\AMS.Eclipse.Agent\eclipse-agent.nuspec.
[11:06:17 ERR] Project C:\Users\jbuedel\Projects\EclipsePro-Design\src\AMS.Eclipse.Agent\AMS.Eclipse.Agent.csproj parsing has thrown an exception, skipping...
System.NullReferenceException: Object reference not set to an instance of an object.
   at void Project2015To2017.Transforms.NuGetPackageTransformation.ConstrainPackageReferences(IReadOnlyList<PackageReference> rawPackageReferences, PackageConfiguration packageConfig)+(XElement dependency) => { } in C:/projects/csprojtovs2017/Project2015To2017.Core/Transforms/NuGetPackageTransformation.cs:line 34
   at TResult[] System.Linq.Enumerable+SelectListIterator<TSource, TResult>.ToArray()
   at TSource[] System.Linq.Enumerable.ToArray<TSource>(IEnumerable<TSource> source)
   at void Project2015To2017.Transforms.NuGetPackageTransformation.ConstrainPackageReferences(IReadOnlyList<PackageReference> rawPackageReferences, PackageConfiguration packageConfig) in C:/projects/csprojtovs2017/Project2015To2017.Core/Transforms/NuGetPackageTransformation.cs:line 34
   at void Project2015To2017.Transforms.NuGetPackageTransformation.Transform(Project definition) in C:/projects/csprojtovs2017/Project2015To2017.Core/Transforms/NuGetPackageTransformation.cs:line 19
   at Project Project2015To2017.ProjectConverter.ProcessProjectFile(FileInfo file, Solution solution, ProjectReference reference) in C:/projects/csprojtovs2017/Project2015To2017.Core/ProjectConverter.cs:line 94
   at (IReadOnlyCollection<Project> projects, IReadOnlyCollection<Solution> solutions) Project2015To2017.MigrationFacility.ParseProjects(IEnumerable<string> items, ITransformationSet transformationSet, ConversionOptions conversionOptions)+ProcessSingleItem(FileInfo file, string extension) in C:/projects/csprojtovs2017/Project2015To2017/MigrationFacility.cs:line 160

While the specs [0] do say that a version attribute is required, this .nuspec is used to create a chocolatey package, and I guess chocolatey isn't so strict.

I get it if you don't care to support a non-standard file format. However it would be nice if the tool gave a better message as to the problem.

[0] https://docs.microsoft.com/en-us/nuget/reference/nuspec#dependencies-element