Code Monkey home page Code Monkey logo

msbuildprediction's Introduction

Microsoft.Build.Prediction

NuGet package NuGet downloads Build Status

This library runs predictors against evaluated MSBuild ProjectInstance to predict file and directory inputs that will be read, and output directories that will be written, by the project.

Predictors are implementations of the IProjectPredictor interface. Execution logic in this library applies the predictors in parallel to a given Project. The library aggregates results from all predictors into a final set of predicted inputs and outputs for a Project.

Input and output predictions produced here can be used, for instance, for Project build caching and sandboxing. Predicted inputs are added to the project file itself and known global files and folders from SDKs and tools to produce a set of files and folders that can be hashed and summarized to produce an inputs hash that can be used to look up the results of previous build executions. The more accurate and complete the predicted set of inputs, the narrower the set of cached output results, and the better the cache performance. Predicted build output directories are used to guide static construction and analysis of build sandboxes.

Usage

Basic usage:

List<IProjectPredictor> predictors = new List<IProjectPredictor>();
predictors.AddRange(ProjectPredictors.AllPredictors);
// Add any custom IProjectPredictor implementations

var predictionExecutor = new ProjectPredictionExecutor(predictors);

ProjectInstance projectInstance = /* Create an MSBuild ProjectInstance */;
ProjectPredictions predictions = predictionExecutor.PredictInputsAndOutputs(projectInstance);

Providing a custom IProjectPredictionCollector:

IReadOnlyCollection<IProjectPredictor> predictors = ProjectPredictors.AllPredictors;

var predictionExecutor = new ProjectPredictionExecutor(predictors);
var predictionCollector = new CustomProjectPredictionCollector();

ProjectInstance projectInstance = /* Create an MSBuild ProjectInstance */;
predictionExecutor.PredictInputsAndOutputs(projectInstance, predictionCollector);

Using alongside MSBuild's ProjectGraph:

string projectFile = /* Your entry project file */;
ProjectCollection projectCollection = ProjectCollection.GlobalProjectCollection;

// Use a shared evaluation context for all projects.
EvaluationContext evaluationContext = EvaluationContext.Create(EvaluationContext.SharingPolicy.Shared);

var projectGraph = new ProjectGraph(
    projectFile,
    projectCollection
    (string projectPath, Dictionary<string, string> globalProperties, ProjectCollection projCollection) =>
    {
        var projectOptions = new ProjectOptions
        {
            GlobalProperties = globalProperties,
            ProjectCollection = projCollection,
            EvaluationContext = evaluationContext,
        };

        return ProjectInstance.FromFile(projectPath, projectOptions);
    });


ProjectInstance[] projectInstances = projectGraph.ProjectNodes.Select(node => node.ProjectInstance).ToArray();

IReadOnlyCollection<IProjectPredictor> predictors = ProjectPredictors.AllPredictors;

// Using single-threaded prediction since we're parallelizing on project instances instead.
var predictionExecutor = new ProjectPredictionExecutor(predictors, new ProjectPredictionOptions { MaxDegreeOfParallelism = 1 });

var predictionCollector = new CustomProjectPredictionCollector();

Parallel.ForEach(
    projectInstances,
    new ParallelOptions() { MaxDegreeOfParallelism = Environment.ProcessorCount },
    project => predictionExecutor.PredictInputsAndOutputs(project, predictionCollector));

Design

See Design.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

msbuildprediction's People

Contributors

andygerlicher avatar bgianfo avatar dfederm avatar microsoft-github-policy-service[bot] avatar microsoftopensource avatar msftgits avatar nayanshah avatar rainersigwald avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

msbuildprediction's Issues

Fix .NET Framework tests

The error is:

The tools version "Current" is unrecognized. Available tools versions are "2.0", "3.5", "4.0".

So it's seemingly picking up MSBuild from the GAC instead of the v17 one we reference.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.