Set Default MSBuild Version? #3044
Replies: 3 comments
-
No. It will always choose the latest MSBuild by default. If you want another one you will have to specify it. |
Beta Was this translation helpful? Give feedback.
-
If the goal is to avoid duplicated code you can create a helper method which returns the settings object with the desired MsBuild version set which you then can pass to the MsBuild alias. With this you can update the version in one place |
Beta Was this translation helpful? Give feedback.
-
One way of doing that would be to leverage Setup And Teardown that can create a brand new instance of Example using a shared MSBuildSettings msbuildSettings = null;
// Runs before every task
TaskSetup(_ =>
{
// Reset the default settings before every task runs
msbuildSettings = new MSBuildSettings
{
ToolVersion = MSBuildToolVersion.VS2019,
};
});
Task("Build")
.Does(_ =>
{
msbuildSettings.Configuration = "Release";
// ... (override other properties of msbuildSettings)
MSBuild("./MyConsoleApp/MyConsoleApp.csproj", msbuildSettings);
});
RunTarget("Build"); Another way (very similar, albeit more verbose) would be to use a typed context to share build state: // Runs only once
Setup<BuildData>(_ =>
{
return new BuildData();
});
// Runs before every task
TaskSetup<BuildData>((_, data) =>
{
// Reset the default settings before every task runs
data.MSBuildSettings = new MSBuildSettings
{
ToolVersion = MSBuildToolVersion.VS2019,
};
});
Task("Build")
.Does<BuildData>(data =>
{
var msbuildSettings = data.MSBuildSettings;
msbuildSettings.Configuration = "Release";
// ... (override other properties of msbuildSettings)
MSBuild("./MyConsoleApp/MyConsoleApp.csproj", msbuildSettings);
});
RunTarget("Build");
public class BuildData
{
public MSBuildSettings MSBuildSettings { get; set; }
} |
Beta Was this translation helpful? Give feedback.
-
Is there a way to set the default MSBuild version so that I don't have to include it on every command?
Beta Was this translation helpful? Give feedback.
All reactions