baseclass / Contrib.Nuget

Extending nuget with nuget packages
MIT License
30 stars 21 forks source link

Exception System.IO.DirectoryNotFoundException in PackageRetrievalTask #44

Closed apermoser closed 6 years ago

apermoser commented 6 years ago

Hi Daniel

I'm migrating from VS2015 to VS2017 with your newsest lib 2.4.1. But unfortunaletly I'm geeting the following exception:

error MSB4018: The "PackageRetrievalTask" task failed unexpectedly. error MSB4018: System.IO.DirectoryNotFoundException: Could not find a part of the path 'B:\dswork_ap\tfs\ds\Releases\20170405\Source\ds-software\packages'. error MSB4018: at System.IO.Error.WinIOError(Int32 errorCode, String maybeFullPath) error MSB4018: at System.IO.FileSystemEnumerableIterator1.CommonInit() error MSB4018: at System.IO.FileSystemEnumerableIterator1..ctor(String path, String originalUserPath, String searchPattern, SearchOption searchOption, SearchResultHandler1 resultHandler, Boolean checkHost) error MSB4018: at System.IO.Directory.EnumerateFiles(String path, String searchPattern, SearchOption searchOption) error MSB4018: at Baseclass.Contrib.Nuget.Output.Build.PackageRetrievalTask.GetFilteredProjectNugetPackages(NugetPackageSource currentNugetPackageSource, HashSet1 usedNugetPackages) error MSB4018: at Baseclass.Contrib.Nuget.Output.Build.PackageRetrievalTask.Execute() error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.d26.MoveNext()

I think your method "GetFilteredProjectNugetPackages" has a bug:

private IEnumerable<string> GetFilteredProjectNugetPackages(NugetPackageSource currentNugetPackageSource, HashSet<string> usedNugetPackages)
{
    string str;
    switch (currentNugetPackageSource)
    {
        case NugetPackageSource.PackagesConfig:
            str = Path.Combine(this.SolutionPath, "packages");
            break;

        case NugetPackageSource.ProjectFile:
            str = Environment.GetEnvironmentVariable("NUGET_PACKAGES") ?? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), @".nuget\packages");
            break;

        default:
            throw new ArgumentOutOfRangeException("currentNugetPackageSource", currentNugetPackageSource, null);
    }
    return (from p in Directory.EnumerateFiles(str, "*.nupkg", SearchOption.AllDirectories)
        where usedNugetPackages.Contains(Path.GetFileNameWithoutExtension(p).ToLowerInvariant())
        select p).ToArray<string>();
}

str = Path.Combine(this.SolutionPath, "packages"); Here you assume the folder "packages" always exists under the solution directory, but that can be changed by a file named "nuget.config":

In my case it looks like this:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <solution>
    <add key="disableSourceControlIntegration" value="true" />
  </solution>
  <config>
    <add key="repositorypath" value="..\..\..\Packages" />
  </config>
</configuration>

With this file I relink the package folder to a new destination and therefore there is no folder "packages" under the solution dir and we are getting the exception "DirectoryNotFoundException" as described above.

Any solution for this?

Thank you very much for your support Andrej

romerod commented 6 years ago

This bugs should be fixed, version 2.4.1 was built from old sources see #43