Esempio n. 1
0
            public CacheWriter(ResolvePackageAssets task, Stream stream = null)
            {
                _targetFramework = NuGetUtils.ParseFrameworkName(task.TargetFrameworkMoniker);

                _task                      = task;
                _lockFile                  = new LockFileCache(task).GetLockFile(task.ProjectAssetsFile);
                _packageResolver           = NuGetPackageResolver.CreateResolver(_lockFile);
                _compileTimeTarget         = _lockFile.GetTargetAndThrowIfNotFound(_targetFramework, runtime: null);
                _runtimeTarget             = _lockFile.GetTargetAndThrowIfNotFound(_targetFramework, _task.RuntimeIdentifier);
                _stringTable               = new Dictionary <string, int>(InitialStringTableCapacity, StringComparer.Ordinal);
                _metadataStrings           = new List <string>(InitialStringTableCapacity);
                _bufferedMetadata          = new List <int>();
                _platformPackageExclusions = GetPlatformPackageExclusions();

                if (stream == null)
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(task.ProjectAssetsCacheFile));
                    stream  = File.Open(task.ProjectAssetsCacheFile, FileMode.Create, FileAccess.ReadWrite, FileShare.None);
                    _writer = new BinaryWriter(stream, TextEncoding, leaveOpen: false);
                }
                else
                {
                    _writer = new BinaryWriter(stream, TextEncoding, leaveOpen: true);
                }
            }
Esempio n. 2
0
        public static ProjectContext CreateProjectContext(
            this LockFile lockFile,
            NuGetFramework framework,
            string runtime,
            //  Trimmed from publish output, and if there are no runtimeFrameworks, written to runtimeconfig.json
            string platformLibraryName,
            //  Written to runtimeconfig.json
            Microsoft.Build.Framework.ITaskItem[] runtimeFrameworks,
            bool isSelfContained)
        {
            if (lockFile == null)
            {
                throw new ArgumentNullException(nameof(lockFile));
            }
            if (framework == null)
            {
                throw new ArgumentNullException(nameof(framework));
            }

            var lockFileTarget = lockFile.GetTargetAndThrowIfNotFound(framework, runtime);

            LockFileTargetLibrary platformLibrary = lockFileTarget.GetLibrary(platformLibraryName);
            bool isFrameworkDependent             = (platformLibrary != null || runtimeFrameworks?.Any() == true) &&
                                                    (!isSelfContained || string.IsNullOrEmpty(lockFileTarget.RuntimeIdentifier));

            return(new ProjectContext(lockFile, lockFileTarget, platformLibrary,
                                      runtimeFrameworks?.Select(i => new ProjectContext.RuntimeFramework(i))?.ToArray(),
                                      isFrameworkDependent));
        }
Esempio n. 3
0
        public ProjectContext(LockFile lockFile, LockFileTarget lockFileTarget,
                              //  Trimmed from publish output, and if there are no runtimeFrameworks, written to runtimeconfig.json
                              LockFileTargetLibrary platformLibrary,
                              //  Written to runtimeconfig.json
                              RuntimeFramework[] runtimeFrameworks,
                              bool isFrameworkDependent)
        {
            Debug.Assert(lockFile != null);
            Debug.Assert(lockFileTarget != null);
            if (isFrameworkDependent)
            {
                Debug.Assert(platformLibrary != null ||
                             (runtimeFrameworks != null && runtimeFrameworks.Any()));
            }

            _lockFile       = lockFile;
            _lockFileTarget = lockFileTarget;
            if (string.IsNullOrEmpty(lockFileTarget.RuntimeIdentifier))
            {
                CompilationLockFileTarget = lockFileTarget;
            }
            else
            {
                CompilationLockFileTarget = lockFile.GetTargetAndThrowIfNotFound(lockFileTarget.TargetFramework, null);
            }

            PlatformLibrary      = platformLibrary;
            RuntimeFrameworks    = runtimeFrameworks;
            IsFrameworkDependent = isFrameworkDependent;
        }
Esempio n. 4
0
            public CacheWriter(ResolvePackageAssets task)
            {
                var targetFramework = NuGetUtils.ParseFrameworkName(task.TargetFrameworkMoniker);

                _task              = task;
                _lockFile          = new LockFileCache(task.BuildEngine4).GetLockFile(task.ProjectAssetsFile);
                _packageResolver   = NuGetPackageResolver.CreateResolver(_lockFile, _task.ProjectPath);
                _compileTimeTarget = _lockFile.GetTargetAndThrowIfNotFound(targetFramework, runtime: null);
                _runtimeTarget     = _lockFile.GetTargetAndThrowIfNotFound(targetFramework, _task.RuntimeIdentifier);
                _stringTable       = new Dictionary <string, int>(InitialStringTableCapacity, StringComparer.Ordinal);
                _metadataStrings   = new List <string>(InitialStringTableCapacity);
                _bufferedMetadata  = new List <int>();

                var stream = File.Open(task.ProjectAssetsCacheFile, FileMode.Create, FileAccess.ReadWrite, FileShare.None);

                _writer = new BinaryWriter(stream, TextEncoding, leaveOpen: false);
            }
Esempio n. 5
0
        private string GetApphostAsset(NuGetFramework targetFramework, LockFile lockFile, string runtimeIdentifier)
        {
            var apphostName = DotNetAppHostExecutableNameWithoutExtension;

            if (runtimeIdentifier.StartsWith("win"))
            {
                apphostName += ".exe";
            }

            LockFileTarget runtimeTarget = lockFile.GetTargetAndThrowIfNotFound(targetFramework, runtimeIdentifier);

            return(FindApphostInRuntimeTarget(apphostName, runtimeTarget));
        }
Esempio n. 6
0
        public static ProjectContext CreateProjectContext(
            this LockFile lockFile,
            NuGetFramework framework,
            string runtime,
            string platformLibraryName,
            bool isSelfContained)
        {
            if (lockFile == null)
            {
                throw new ArgumentNullException(nameof(lockFile));
            }
            if (framework == null)
            {
                throw new ArgumentNullException(nameof(framework));
            }

            var lockFileTarget = lockFile.GetTargetAndThrowIfNotFound(framework, runtime);

            LockFileTargetLibrary platformLibrary = lockFileTarget.GetLibrary(platformLibraryName);
            bool isFrameworkDependent             = platformLibrary != null && (!isSelfContained || string.IsNullOrEmpty(lockFileTarget.RuntimeIdentifier));

            return(new ProjectContext(lockFile, lockFileTarget, platformLibrary, isFrameworkDependent));
        }