RB.
RB.

Reputation: 37192

Is there a property I can use to detect when I am building with MSBuildWorkspace

Inside my .csproj file, is there a property I can use to detect the project file is being built by MSBuildWorkspace (as opposed to msbuild directly)?

Basically, I have a csproj file that executes an exe.

The exe takes the project file as input, builds it using MSBuildWorkspace, and then generates some additional files based on the compilation.

However, every time I build it, it is causing the csproj file to execute the exe - and so I have made myself a fork bomb!

I want to stop this happening...

Upvotes: 0

Views: 93

Answers (1)

RB.
RB.

Reputation: 37192

The answer is actually really simple it turns out!

You can supply properties to MSBuildWorkspace.Create that are passed to the csproj files, e.g.:

var properties = new Dictionary<string, string>
{   
    ["Tools_BuildingInsideGenerator"] = "true"
};

using (workspace = MSBuildWorkspace.Create(properties))
{
}

Upvotes: 1

Related Questions