Example #1
0
        /// <summary>
        ///     Factory for <see cref="EvaluationContext" />
        /// </summary>
        /// <param name="policy"> The <see cref="SharingPolicy"/> to use.</param>
        /// <param name="fileSystem">The <see cref="IFileSystem"/> to use.
        ///     This parameter is compatible only with <see cref="SharingPolicy.Shared"/>.
        ///     The method throws if a file system is used with <see cref="SharingPolicy.Isolated"/>.
        ///     The reasoning is that <see cref="SharingPolicy.Isolated"/> means not reusing any caches between evaluations,
        ///     and the passed in <paramref name="fileSystem"/> might cache state.
        /// </param>
        public static EvaluationContext Create(SharingPolicy policy, MSBuildFileSystemBase fileSystem)
        {
            var context = new EvaluationContext(
                policy,
                fileSystem);

            TestOnlyHookOnCreate?.Invoke(context);

            return(context);
        }
Example #2
0
        /// <summary>
        ///     Factory for <see cref="EvaluationContext" />
        /// </summary>
        /// <param name="policy"> The <see cref="SharingPolicy"/> to use.</param>
        /// <param name="fileSystem">The <see cref="IFileSystem"/> to use.
        ///     This parameter is compatible only with <see cref="SharingPolicy.Shared"/>.
        ///     The method throws if a file system is used with <see cref="SharingPolicy.Isolated"/>.
        ///     The reasoning is that <see cref="SharingPolicy.Isolated"/> means not reusing any caches between evaluations,
        ///     and the passed in <paramref name="fileSystem"/> might cache state.
        /// </param>
        public static EvaluationContext Create(SharingPolicy policy, MSBuildFileSystemBase fileSystem)
        {
            // Unsupported case: isolated context with non null file system.
            // Isolated means caches aren't reused, but the given file system might cache.
            ErrorUtilities.VerifyThrowArgument(
                policy == SharingPolicy.Shared || fileSystem == null,
                "IsolatedContextDoesNotSupportFileSystem");

            var context = new EvaluationContext(
                policy,
                fileSystem);

            TestOnlyHookOnCreate?.Invoke(context);

            return(context);
        }
Example #3
0
        public CacheContext(
            IReadOnlyDictionary <string, string> pluginSettings,
            MSBuildFileSystemBase fileSystem,
            ProjectGraph?graph = null,
            IReadOnlyCollection <ProjectGraphEntryPoint>?graphEntryPoints = null)
        {
            ErrorUtilities.VerifyThrow(
                (graph != null) ^ (graphEntryPoints != null),
                "Either Graph is specified, or GraphEntryPoints is specified. Not both.");

            PluginSettings   = pluginSettings;
            Graph            = graph;
            GraphEntryPoints = graphEntryPoints;
            MSBuildExePath   = BuildEnvironmentHelper.Instance.CurrentMSBuildExePath;
            FileSystem       = fileSystem;
        }