Esempio n. 1
0
        public MSBuildProjectDescription GetDescription(NuGetFramework targetFramework, LockFileProjectLibrary projectLibrary, LockFileTargetLibrary targetLibrary)
        {
            var compatible = targetLibrary.FrameworkAssemblies.Any() ||
                             targetLibrary.CompileTimeAssemblies.Any() ||
                             targetLibrary.RuntimeAssemblies.Any();

            var dependencies = new List<LibraryRange>(targetLibrary.Dependencies.Count + targetLibrary.FrameworkAssemblies.Count);
            PopulateDependencies(dependencies, targetLibrary, targetFramework);

            var msbuildProjectFilePath = GetMSBuildProjectFilePath(projectLibrary);
            var msbuildProjectDirectoryPath = Path.GetDirectoryName(msbuildProjectFilePath);

            var exists = Directory.Exists(msbuildProjectDirectoryPath);

            var projectFile = projectLibrary.Path == null ? null : _projectResolver(projectLibrary.Path);

            var msbuildPackageDescription = new MSBuildProjectDescription(
                msbuildProjectDirectoryPath,
                msbuildProjectFilePath,
                projectLibrary,
                targetLibrary,
                projectFile,
                dependencies,
                compatible,
                resolved: compatible && exists);

            return msbuildPackageDescription;
        }
Esempio n. 2
0
 private static IList<LockFileTargetLibrary> GetTargetsForLibrary(LockFile lockFile, LockFileProjectLibrary library)
 {
     return lockFile.Targets
         .SelectMany(
             t => t.Libraries
                 .Where(
                     l => string.Equals(GetProjectLibraryKey(library), (GetTargetLibraryKey(l)))
                     )
             )
         .ToList();
 }
Esempio n. 3
0
        private void ReadLibrary(JObject json, LockFile lockFile)
        {
            if (json == null)
            {
                return;
            }

            foreach (var child in json)
            {
                var key   = child.Key;
                var value = json.Value <JObject>(key);
                if (value == null)
                {
                    throw FileFormatException.Create("The value type is not object.", json[key]);
                }

                var parts   = key.Split(new[] { '/' }, 2);
                var name    = parts[0];
                var version = parts.Length == 2 ? _symbols.GetVersion(parts[1]) : null;

                var type = _symbols.GetString(value.Value <string>("type"));

                var pathValue = value["path"];
                var path      = pathValue == null ? null : ReadString(pathValue);

                if (type == null || string.Equals(type, "package", StringComparison.OrdinalIgnoreCase))
                {
                    lockFile.PackageLibraries.Add(new LockFilePackageLibrary
                    {
                        Name          = name,
                        Version       = version,
                        IsServiceable = ReadBool(value, "serviceable", defaultValue: false),
                        Sha512        = ReadString(value["sha512"]),
                        Files         = ReadPathArray(value["files"], ReadString),
                        Path          = path
                    });
                }
                else if (type == "project")
                {
                    var projectLibrary = new LockFileProjectLibrary
                    {
                        Name    = name,
                        Version = version
                    };

                    projectLibrary.Path = path;

                    var buildTimeDependencyValue = value["msbuildProject"];
                    projectLibrary.MSBuildProject = buildTimeDependencyValue == null ? null : ReadString(buildTimeDependencyValue);

                    lockFile.ProjectLibraries.Add(projectLibrary);
                }
            }
        }
Esempio n. 4
0
        private string GetMSBuildProjectFilePath(LockFileProjectLibrary projectLibrary)
        {
            if (_rootProject == null)
            {
                throw new InvalidOperationException("Root xproj project does not exist. Cannot compute the path of its referenced csproj projects.");
            }

            var rootProjectPath = Path.GetDirectoryName(_rootProject.ProjectFilePath);
            var msbuildProjectFilePath = Path.Combine(rootProjectPath, projectLibrary.MSBuildProject);

            return Path.GetFullPath(msbuildProjectFilePath);
        }
Esempio n. 5
0
        private static void ReadLibrary(JsonObject json, LockFile lockFile)
        {
            if (json == null)
            {
                return;
            }

            foreach (var key in json.Keys)
            {
                var value = json.ValueAsJsonObject(key);
                if (value == null)
                {
                    throw FileFormatException.Create("The value type is not object.", json.Value(key));
                }

                var parts   = key.Split(new[] { '/' }, 2);
                var name    = parts[0];
                var version = parts.Length == 2 ? NuGetVersion.Parse(parts[1]) : null;

                var type = value.ValueAsString("type")?.Value;

                if (type == null || string.Equals(type, "package", StringComparison.OrdinalIgnoreCase))
                {
                    lockFile.PackageLibraries.Add(new LockFilePackageLibrary
                    {
                        Name          = name,
                        Version       = version,
                        IsServiceable = ReadBool(value, "serviceable", defaultValue: false),
                        Sha512        = ReadString(value.Value("sha512")),
                        Files         = ReadPathArray(value.Value("files"), ReadString)
                    });
                }
                else if (type == "project")
                {
                    var projectLibrary = new LockFileProjectLibrary
                    {
                        Name    = name,
                        Version = version
                    };

                    var pathValue = value.Value("path");
                    projectLibrary.Path = pathValue == null ? null : ReadString(pathValue);

                    var buildTimeDependencyValue = value.Value("msbuildProject");
                    projectLibrary.MSBuildProject = buildTimeDependencyValue == null ? null : ReadString(buildTimeDependencyValue);

                    lockFile.ProjectLibraries.Add(projectLibrary);
                }
            }
        }
 public MSBuildProjectDescription(
     string path,
     string msbuildProjectPath,
     LockFileProjectLibrary projectLibrary,
     LockFileTargetLibrary lockFileLibrary,
     Project projectFile,
     IEnumerable<LibraryRange> dependencies,
     bool compatible,
     bool resolved)
     : base(
           new LibraryIdentity(projectLibrary.Name, projectLibrary.Version, LibraryType.MSBuildProject),
           string.Empty, //msbuild projects don't have hashes
           path,
           lockFileLibrary,
           dependencies,
           resolved: resolved,
           compatible: compatible,
           framework: null)
 {
     MSBuildProjectPath = msbuildProjectPath;
     ProjectFile = projectFile;
     ProjectLibrary = projectLibrary;
 }
Esempio n. 7
0
 private static IList <LockFileTargetLibrary> GetTargetsForLibrary(LockFile lockFile, LockFileProjectLibrary library)
 {
     return(lockFile.Targets
            .SelectMany(
                t => t.Libraries
                .Where(
                    l => string.Equals(GetProjectLibraryKey(library), (GetTargetLibraryKey(l)))
                    )
                )
            .ToList());
 }
Esempio n. 8
0
 private static string GetProjectLibraryKey(LockFileProjectLibrary library)
 {
     return(library.Name + "/" + library.Version);
 }
Esempio n. 9
0
 private static string GetProjectLibraryKey(LockFileProjectLibrary library)
 {
     return library.Name + "/" + library.Version;
 }
Esempio n. 10
0
        public static bool IsMSBuildProjectLibrary(LockFileProjectLibrary projectLibrary)
        {
            var msbuildProjectPath = projectLibrary.MSBuildProject;
            if (msbuildProjectPath == null)
            {
                return false;
            }

            var extension = Path.GetExtension(msbuildProjectPath);

            return !string.Equals(extension, ".xproj", StringComparison.OrdinalIgnoreCase);
        }