Example #1
0
        public DependencyContextBuilder(
            SingleProjectInfo mainProjectInfo,
            bool includeRuntimeFileVersions,
            ITaskItem[] runtimeFrameworks,
            string runtimeIdentifier,
            bool isSelfContained,
            string platformLibraryName,
            string targetFramework)
        {
            _mainProjectInfo            = mainProjectInfo;
            _includeRuntimeFileVersions = includeRuntimeFileVersions;

            _isFrameworkDependent = LockFileExtensions.IsFrameworkDependent(
                runtimeFrameworks,
                isSelfContained,
                runtimeIdentifier,
                string.IsNullOrWhiteSpace(platformLibraryName));

            _isPortable = _isFrameworkDependent && string.IsNullOrEmpty(_runtimeIdentifier);

            if (_isFrameworkDependent != true || _isPortable != true)
            {
                throw new ArgumentException(
                          $"{nameof(DependencyContextBuilder)} Does not support non FrameworkDependent without assetfile. " +
                          $"runtimeFrameworks: {string.Join(",", runtimeFrameworks.Select(r => r.ItemSpec))} " +
                          $"isSelfContained: {isSelfContained} " +
                          $"runtimeIdentifier: {runtimeIdentifier} " +
                          $"platformLibraryName: {platformLibraryName}");
            }

            _platformLibrary = platformLibraryName;

            //  NOTE: This uses the TargetFramework (ie "net5.0") as the deps.json runtimeTarget name, instead of
            //  the TargetFrameworkMoniker (ie ".NETCoreApp,Version=v5.0"), which is normally used.
            //
            //  This constructor should only be used for C++/CLI, and is used because PackageReference isn't
            //  currently supported in that context so there is no assets file to read from.
            //
            //  Using the TargetFramework instead should have minimal impact.
            _dotnetFrameworkName = targetFramework;
            _runtimeIdentifier   = runtimeIdentifier;

            _dependencyLibraries     = new Dictionary <string, DependencyLibrary>();
            _libraryDependencies     = new Dictionary <string, List <LibraryDependency> >();
            _mainProjectDependencies = new List <string>();
            _packagesToBeFiltered    = null;

            _usedLibraryNames = new HashSet <string>();
        }
        public DependencyContextBuilder(
            SingleProjectInfo mainProjectInfo,
            bool includeRuntimeFileVersions,
            ITaskItem[] runtimeFrameworks,
            string runtimeIdentifier,
            bool isSelfContained,
            string platformLibraryName,
            string targetFramework)
        {
            _mainProjectInfo            = mainProjectInfo;
            _includeRuntimeFileVersions = includeRuntimeFileVersions;

            _isFrameworkDependent = LockFileExtensions.IsFrameworkDependent(
                runtimeFrameworks,
                isSelfContained,
                runtimeIdentifier,
                string.IsNullOrWhiteSpace(platformLibraryName));

            _isPortable = _isFrameworkDependent && string.IsNullOrEmpty(_runtimeIdentifier);

            if (_isFrameworkDependent != true || _isPortable != true)
            {
                throw new ArgumentException(
                          $"{nameof(DependencyContextBuilder)} Does not support non FrameworkDependent without assetfile. " +
                          $"runtimeFrameworks: {string.Join(",", runtimeFrameworks.Select(r => r.ItemSpec))} " +
                          $"isSelfContained: {isSelfContained} " +
                          $"runtimeIdentifier: {runtimeIdentifier} " +
                          $"platformLibraryName: {platformLibraryName}");
            }

            _platformLibrary     = platformLibraryName;
            _dotnetFrameworkName = targetFramework;
            _runtimeIdentifier   = runtimeIdentifier;

            _dependencyLibraries     = new Dictionary <string, DependencyLibrary>();
            _libraryDependencies     = new Dictionary <string, List <LibraryDependency> >();
            _mainProjectDependencies = new List <string>();
            _packagesToBeFiltered    = null;

            _usedLibraryNames = new HashSet <string>();
        }
Example #3
0
        protected override void ExecuteCore()
        {
            bool writeDevRuntimeConfig = !string.IsNullOrEmpty(RuntimeConfigDevPath);

            if (!WriteAdditionalProbingPathsToMainConfig)
            {
                if (AdditionalProbingPaths?.Any() == true && !writeDevRuntimeConfig)
                {
                    Log.LogWarning(Strings.SkippingAdditionalProbingPaths);
                }
            }

            if (!string.IsNullOrEmpty(RollForward))
            {
                if (!RollForwardValues.Any(v => string.Equals(RollForward, v, StringComparison.OrdinalIgnoreCase)))
                {
                    Log.LogError(Strings.InvalidRollForwardValue, RollForward, string.Join(", ", RollForwardValues));
                    return;
                }
            }

            if (AssetsFilePath == null)
            {
                var isFrameworkDependent = LockFileExtensions.IsFrameworkDependent(
                    RuntimeFrameworks,
                    IsSelfContained,
                    RuntimeIdentifier,
                    string.IsNullOrWhiteSpace(PlatformLibraryName));

                if (isFrameworkDependent != true)
                {
                    throw new ArgumentException(
                              $"{nameof(DependencyContextBuilder)} Does not support non FrameworkDependent without asset file. " +
                              $"runtimeFrameworks: {string.Join(",", RuntimeFrameworks.Select(r => r.ItemSpec))} " +
                              $"isSelfContained: {IsSelfContained} " +
                              $"runtimeIdentifier: {RuntimeIdentifier} " +
                              $"platformLibraryName: {PlatformLibraryName}");
                }

                if (PlatformLibraryName != null)
                {
                    throw new ArgumentException(
                              "Does not support non null PlatformLibraryName(TFM < 3) without asset file.");
                }

                WriteRuntimeConfig(
                    RuntimeFrameworks.Select(r => new ProjectContext.RuntimeFramework(r)).ToArray(),
                    null,
                    isFrameworkDependent: true, new List <LockFileItem>());
            }
            else
            {
                LockFile lockFile = new LockFileCache(this).GetLockFile(AssetsFilePath);

                ProjectContext projectContext = lockFile.CreateProjectContext(
                    NuGetUtils.ParseFrameworkName(TargetFrameworkMoniker),
                    RuntimeIdentifier,
                    PlatformLibraryName,
                    RuntimeFrameworks,
                    IsSelfContained);

                WriteRuntimeConfig(projectContext.RuntimeFrameworks,
                                   projectContext.PlatformLibrary,
                                   projectContext.IsFrameworkDependent,
                                   projectContext.LockFile.PackageFolders);

                if (writeDevRuntimeConfig)
                {
                    WriteDevRuntimeConfig(projectContext.LockFile.PackageFolders);
                }
            }
        }