Search code examples
.netwindowsmsbuildroslyn

How to build just the source code in the given project using msbuild or Roslyn?


I have a project that depends on many other projects. I made a change in the source code of that project. If I run msbuild on that project, it would go through all of its dependency projects. It would not reach to the actual compilation, because they did not change, but it would still take it quite some time to figure out that nothing needs to be done there.

I am looking for a way to check that the code just in the given project compiles without spending any extra cycles on other projects. I know Roslyn can do it - Edit and Continue does it during debugging.

How can I do it myself? Either with msbuild (if there is a hidden way to do it) or with Roslyn API.


Solution

  • You can use BuildProjectReferences property to avoid building referenced projects

    dotnet build --project path_to_project.csproj /p:BuildProjectReferences=false
    

    Or if you want to always avoid building referenced projects add this property to project file

    <PropertyGroup>
        <BuildProjectReferences>false</BuildProjectReferences>
    </PropertyGroup>