private static DirectoryPath GetFrameworkPath(ICakeEnvironment environment, MSBuildPlatform buildPlatform, string version) { // Get the Microsoft .NET folder. var windowsFolder = environment.GetSpecialPath(SpecialPath.Windows); var netFolder = windowsFolder.Combine("Microsoft.NET"); if (buildPlatform == MSBuildPlatform.Automatic) { // Get the framework folder. var is64Bit = environment.Platform.Is64Bit; var frameWorkFolder = is64Bit ? netFolder.Combine("Framework64") : netFolder.Combine("Framework"); return(frameWorkFolder.Combine(version)); } if (buildPlatform == MSBuildPlatform.x86) { return(netFolder.Combine("Framework").Combine(version)); } if (buildPlatform == MSBuildPlatform.x64) { return(netFolder.Combine("Framework64").Combine(version)); } throw new NotSupportedException(); }
private static DirectoryPath GetVisualStudio2019Path(IFileSystem fileSystem, ICakeEnvironment environment, MSBuildPlatform buildPlatform) { var vsEditions = new[] { "Enterprise", "Professional", "Community", "BuildTools" }; var visualStudio2019Path = environment.GetSpecialPath(SpecialPath.ProgramFilesX86); foreach (var edition in vsEditions) { // Get the bin path. var binPath = visualStudio2019Path.Combine(string.Concat("Microsoft Visual Studio/2019/", edition, "/MSBuild/Current/Bin")); // Change from Current to 16.0 after stable version released if (fileSystem.Exist(binPath)) { if (buildPlatform == MSBuildPlatform.Automatic) { if (environment.Platform.Is64Bit) { binPath = binPath.Combine("amd64"); } } if (buildPlatform == MSBuildPlatform.x64) { binPath = binPath.Combine("amd64"); } return(binPath); } } return(visualStudio2019Path.Combine("Microsoft Visual Studio/2019/Professional/MSBuild/16.0/Bin")); }
/// <summary> /// Gets alternative file paths which the tool may exist in /// </summary> /// <param name="settings">The settings.</param> /// <returns>The default tool path.</returns> protected override IEnumerable <FilePath> GetAlternativeToolPaths(MSBuildSettings settings) { if (settings == null) { throw new ArgumentNullException("settings"); } MSBuildPlatform buildPlatform = settings.MSBuildPlatform; // If we haven't explicitly set an MSBuild target then use the Platform Target if (buildPlatform == MSBuildPlatform.Automatic) { switch (settings.PlatformTarget) { case PlatformTarget.x86: buildPlatform = MSBuildPlatform.x86; break; case PlatformTarget.x64: buildPlatform = MSBuildPlatform.x64; break; } } var path = MSBuildResolver.GetMSBuildPath(_fileSystem, _environment, settings.ToolVersion, buildPlatform); if (path != null) { return(new[] { path }); } return(Enumerable.Empty <FilePath>()); }
private static DirectoryPath GetVisualStudio2022Path(IFileSystem fileSystem, ICakeEnvironment environment, MSBuildPlatform buildPlatform, bool allowPreviewVersion) { foreach (var edition in allowPreviewVersion ? VisualStudio.Editions.All : VisualStudio.Editions.Stable) { // Get the bin path. var binPath = VisualStudio.GetYearAndEditionRootPath(environment, "2022", edition).Combine("MSBuild/Current/Bin"); if (fileSystem.Exist(binPath)) { if (buildPlatform == MSBuildPlatform.Automatic) { if (environment.Platform.Is64Bit) { binPath = binPath.Combine("amd64"); } } if (buildPlatform == MSBuildPlatform.x64) { binPath = binPath.Combine("amd64"); } return(binPath); } } return(VisualStudio.GetYearAndEditionRootPath(environment, "2022", "Professional").Combine("MSBuild/Current/Bin")); }
private static string GetFrameworkPath(MSBuildPlatform buildPlatform, string version) { // Get the Microsoft .NET folder. var windowsFolder = Environment.GetFolderPath(System.Environment.SpecialFolder.Windows); var netFolder = Path.Combine(windowsFolder, "Microsoft.NET"); if (buildPlatform == MSBuildPlatform.Automatic) { // Get the framework folder. var is64Bit = System.Environment.Is64BitOperatingSystem; var frameWorkFolder = is64Bit ? Path.Combine(netFolder, "Framework64") : Path.Combine(netFolder, "Framework"); return(Path.Combine(frameWorkFolder, version)); } if (buildPlatform == MSBuildPlatform.x86) { return(Path.Combine(netFolder, "Framework", version)); } if (buildPlatform == MSBuildPlatform.x64) { return(Path.Combine(netFolder, "Framework64", version)); } throw new NotSupportedException(); }
public static void Run(string file, string args, VSVersion vs, MSBuildPlatform platform) { string msbuild = null; paths.Clear(); if (vs == VSVersion.VS2019) { msbuild = VSPath("2019", _editions, "Current", platform); if (msbuild == null) { msbuild = VSPath("2019", _editions, "16.0", platform); } } if (vs == VSVersion.VS2022) { msbuild = VSPath("2022", _editions, "Current", platform); if (msbuild == null) { msbuild = VSPath("2022", _editions, "17.0", platform); } } if (msbuild == null) { foreach (var p in paths) { Console.WriteLine("Tried: {0}", p); } throw new Exception($"Could not find installed MSBuild for {vs} {platform}"); } RunCommand(msbuild, $"{Quote(file)} {args}"); }
private static Instance GetVs2017Instance(MSBuildPlatform platform, string vs2017Edition) { var basePath = Path.Combine( EnvironmentInfo.SpecialFolder(SpecialFolders.ProgramFilesX86).NotNull("path1 != null"), $@"Microsoft Visual Studio\2017\{vs2017Edition}\MSBuild\{GetVersionFolder(MSBuildVersion.VS2017)}\Bin"); return(new Instance( MSBuildVersion.VS2017, platform, platform == MSBuildPlatform.x64 ? Path.Combine(basePath, "amd64") : basePath)); }
private static Instance GetVs2013To2015Instance(MSBuildPlatform platform, MSBuildVersion version) { var basePath = Path.Combine( EnvironmentInfo.SpecialFolder(SpecialFolders.ProgramFilesX86).NotNull("path1 != null"), $@"MSBuild\{GetVersionFolder(version)}\Bin"); return(new Instance( version, platform, platform == MSBuildPlatform.x64 ? Path.Combine(basePath, "amd64") : basePath)); }
private static Instance GetFromVs2017Instance(MSBuildVersion version, MSBuildPlatform platform, string edition) { var versionDirectoryName = version.ToString().TrimStart("VS"); var basePath = Path.Combine( EnvironmentInfo.SpecialFolder(SpecialFolders.ProgramFilesX86).NotNull("path1 != null"), $@"Microsoft Visual Studio\{versionDirectoryName}\{edition}\MSBuild\{GetVersionFolder(version)}\Bin"); return(new Instance( version, platform, platform == MSBuildPlatform.x64 ? Path.Combine(basePath, "amd64") : basePath)); }
public static string GetMSBuildPath(MSBuildPlatform platform = MSBuildPlatform.Automatic, MSBuildToolVersion version = MSBuildToolVersion.Default) { var binPath = version == MSBuildToolVersion.Default ? GetHighestAvailableMSBuildVersion(platform) : GetMSBuildPath((MSBuildVersion)version, platform); if (binPath == null) { throw new Exception("Could not resolve MSBuild."); } // Get the MSBuild path. return(Path.Combine(binPath, "msbuild.exe")); }
private static DirectoryPath GetMSBuildPath( IFileSystem fileSystem, ICakeEnvironment environment, MSBuildVersion version, MSBuildPlatform buildPlatform, string customVersion, bool allowPreview) { switch (version) { case MSBuildVersion.MSBuild17: return(GetVisualStudio2022Path(fileSystem, environment, buildPlatform, allowPreview)); case MSBuildVersion.MSBuild16: return(GetVisualStudio2019Path(fileSystem, environment, buildPlatform, allowPreview)); case MSBuildVersion.MSBuild15: return(GetVisualStudio2017Path(fileSystem, environment, buildPlatform, allowPreview)); case MSBuildVersion.MSBuild14: return(GetVisualStudioPath(environment, buildPlatform, "14.0")); case MSBuildVersion.MSBuild12: return(GetVisualStudioPath(environment, buildPlatform, "12.0")); case MSBuildVersion.MSBuildCustomVS: return(GetVisualStudioPath(environment, buildPlatform, customVersion)); case MSBuildVersion.MSBuild4: return(GetFrameworkPath(environment, buildPlatform, "v4.0.30319")); case MSBuildVersion.MSBuild35: return(GetFrameworkPath(environment, buildPlatform, "v3.5")); case MSBuildVersion.MSBuild20: return(GetFrameworkPath(environment, buildPlatform, "v2.0.50727")); case MSBuildVersion.MSBuildNETCustom: if (!customVersion.Contains("v")) { customVersion = "v" + customVersion; } return(GetFrameworkPath(environment, buildPlatform, customVersion)); default: return(null); } }
private static DirectoryPath GetVisualStudio2022Path(IFileSystem fileSystem, ICakeEnvironment environment, MSBuildPlatform buildPlatform) { var vsEditions = new[] { "Enterprise", "Professional", "Community", "BuildTools", }; var visualStudio2022Paths = new[] { environment.GetSpecialPath(SpecialPath.ProgramFiles), environment.GetSpecialPath(SpecialPath.ProgramFilesX86), }; foreach (var visualStudio2022Path in visualStudio2022Paths) { foreach (var edition in vsEditions) { // Get the bin path. var binPath = visualStudio2022Path.Combine(string.Concat("Microsoft Visual Studio/2022/", edition, "/MSBuild/Current/Bin")); if (fileSystem.Exist(binPath)) { if (buildPlatform == MSBuildPlatform.Automatic) { if (environment.Platform.Is64Bit) { binPath = binPath.Combine("amd64"); } } if (buildPlatform == MSBuildPlatform.x64) { binPath = binPath.Combine("amd64"); } return(binPath); } } } return(visualStudio2022Paths[0].Combine("Microsoft Visual Studio/2022/Professional/MSBuild/Current/Bin")); }
private static string GetVisualStudioPath(MSBuildPlatform buildPlatform, string version) { // Get the bin path. var programFilesPath = Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFilesX86); var binPath = Path.Combine(programFilesPath, "MSBuild", version, "Bin"); if (buildPlatform == MSBuildPlatform.Automatic) { if (System.Environment.Is64BitOperatingSystem) { binPath = Path.Combine(binPath, "amd64"); } } if (buildPlatform == MSBuildPlatform.x64) { binPath = Path.Combine(binPath, "amd64"); } return(binPath); }
public static string GetBuildAssemblyPath(string assemblyName, MSBuildPlatform platform = MSBuildPlatform.Automatic, MSBuildToolVersion version = MSBuildToolVersion.Default, Action <string> logCallback = null) { logCallback = logCallback ?? Console.WriteLine; var binPath = version == MSBuildToolVersion.Default ? GetHighestAvailableMSBuildVersion(platform) : GetMSBuildPath((MSBuildVersion)version, platform); // Get the MSBuild path. if (binPath == null || !File.Exists(Path.Combine(binPath, $"{assemblyName}.dll"))) { logCallback?.Invoke($"Could not locate assembly {assemblyName}"); return(null); } else { logCallback?.Invoke($"Found {assemblyName} at {binPath}"); return(Path.Combine(binPath, $"{assemblyName}.dll")); } }
private static string GetHighestAvailableMSBuildVersion(MSBuildPlatform buildPlatform) { var versions = new[] { MSBuildVersion.MSBuild14, MSBuildVersion.MSBuild12, MSBuildVersion.MSBuild4, MSBuildVersion.MSBuild35, MSBuildVersion.MSBuild20 }; foreach (var version in versions) { var path = GetMSBuildPath(version, buildPlatform); if (Directory.Exists(path)) { return(path); } } return(null); }
private static string GetMSBuildPath(MSBuildVersion version, MSBuildPlatform platform) { switch (version) { case MSBuildVersion.MSBuild14: return(GetVisualStudioPath(platform, "14.0")); case MSBuildVersion.MSBuild12: return(GetVisualStudioPath(platform, "12.0")); case MSBuildVersion.MSBuild4: return(GetFrameworkPath(platform, "v4.0.30319")); case MSBuildVersion.MSBuild35: return(GetFrameworkPath(platform, "v3.5")); case MSBuildVersion.MSBuild20: return(GetFrameworkPath(platform, "v2.0.50727")); default: return(null); } }
static string VSPath(string ver, string[] editions, string msbuildVer, MSBuildPlatform platform) { var pg = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86); if (ver == "2022") { pg = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); //2022 is 64-bit } foreach (var e in editions) { var bin = Path.Combine(pg, "Microsoft Visual Studio", ver, e, "MSBuild", msbuildVer, "Bin"); paths.Add(bin); if (Directory.Exists(bin)) { if (platform == MSBuildPlatform.x64) { return(Path.Combine(bin, "amd64", "MSBuild.exe")); } return(Path.Combine(bin, "MSBuild.exe")); } } return(null); }
private static DirectoryPath GetMSBuildPath(ICakeEnvironment environment, MSBuildVersion version, MSBuildPlatform buildPlatform) { switch (version) { case MSBuildVersion.MSBuild14: return(GetVisualStudioPath(environment, buildPlatform, "14.0")); case MSBuildVersion.MSBuild12: return(GetVisualStudioPath(environment, buildPlatform, "12.0")); case MSBuildVersion.MSBuild4: return(GetFrameworkPath(environment, buildPlatform, "v4.0.30319")); case MSBuildVersion.MSBuild35: return(GetFrameworkPath(environment, buildPlatform, "v3.5")); case MSBuildVersion.MSBuild20: return(GetFrameworkPath(environment, buildPlatform, "v2.0.50727")); default: return(null); } }
private static DirectoryPath GetHighestAvailableMSBuildVersion(IFileSystem fileSystem, ICakeEnvironment environment, MSBuildPlatform buildPlatform) { var versions = new[] { // MSBuildVersion.MSBuild17, /*Since it's still in preview, do not search unless specified. Uncomment after stable version released*/ MSBuildVersion.MSBuild16, MSBuildVersion.MSBuild15, MSBuildVersion.MSBuild14, MSBuildVersion.MSBuild12, MSBuildVersion.MSBuild4, MSBuildVersion.MSBuild35, MSBuildVersion.MSBuild20, }; foreach (var version in versions) { var path = GetMSBuildPath(fileSystem, environment, version, buildPlatform, null); if (fileSystem.Exist(path)) { return(path); } } return(null); }
/// <summary> /// Sets the MSBuild platform. /// </summary> /// <param name="settings">The settings.</param> /// <param name="platform">The platform.</param> /// <returns>The same <see cref="MSBuildSettings"/> instance so that multiple calls can be chained.</returns> public static MSBuildSettings SetMSBuildPlatform(this MSBuildSettings settings, MSBuildPlatform platform) { if (settings == null) { throw new ArgumentNullException(nameof(settings)); } settings.MSBuildPlatform = platform; return(settings); }
public static FilePath GetMSBuildPath(IFileSystem fileSystem, ICakeEnvironment environment, MSBuildToolVersion version, MSBuildPlatform buildPlatform) { if (environment.Platform.Family == PlatformFamily.OSX) { var macMSBuildPath = new FilePath("/Library/Frameworks/Mono.framework/Versions/Current/Commands/msbuild"); if (fileSystem.Exist(macMSBuildPath)) { return(macMSBuildPath); } var brewMSBuildPath = new FilePath("/usr/local/bin/msbuild"); if (fileSystem.Exist(brewMSBuildPath)) { return(brewMSBuildPath); } throw new CakeException("Could not resolve MSBuild."); } else if (environment.Platform.Family == PlatformFamily.Linux) { var linuxMSBuildPath = new FilePath("/usr/bin/msbuild"); if (fileSystem.Exist(linuxMSBuildPath)) { return(linuxMSBuildPath); } throw new CakeException("Could not resolve MSBuild."); } var binPath = version == MSBuildToolVersion.Default ? GetHighestAvailableMSBuildVersion(fileSystem, environment, buildPlatform) : GetMSBuildPath(fileSystem, environment, (MSBuildVersion)version, buildPlatform); if (binPath == null) { throw new CakeException("Could not resolve MSBuild."); } // Get the MSBuild path. return(binPath.CombineWithFilePath("MSBuild.exe")); }
public static FilePath GetMSBuildPath(IFileSystem fileSystem, ICakeEnvironment environment, MSBuildToolVersion version, MSBuildPlatform buildPlatform) { var binPath = version == MSBuildToolVersion.Default ? GetHighestAvailableMSBuildVersion(fileSystem, environment, buildPlatform) : GetMSBuildPath(environment, (MSBuildVersion)version, buildPlatform); if (binPath == null) { throw new CakeException("Could not resolve MSBuild."); } // Get the MSBuild path. return(binPath.CombineWithFilePath("MSBuild.exe")); }
private static DirectoryPath GetHighestAvailableMSBuildVersion(IFileSystem fileSystem, ICakeEnvironment environment, MSBuildPlatform buildPlatform) { var versions = new[] { MSBuildVersion.MSBuild14, MSBuildVersion.MSBuild12, MSBuildVersion.MSBuild4, MSBuildVersion.MSBuild35, MSBuildVersion.MSBuild20 }; foreach (var version in versions) { var path = GetMSBuildPath(environment, version, buildPlatform); if (fileSystem.Exist(path)) { return(path); } } return(null); }
public Instance(MSBuildVersion version, MSBuildPlatform platform, string directory) { Platform = platform; Version = version; ToolPath = Path.Combine(directory, "msbuild.exe"); }
private static DirectoryPath GetVisualStudioPath(ICakeEnvironment environment, MSBuildPlatform buildPlatform, string version) { // Get the bin path. var programFilesPath = environment.GetSpecialPath(SpecialPath.ProgramFilesX86); var binPath = programFilesPath.Combine(string.Concat("MSBuild/", version, "/Bin")); if (buildPlatform == MSBuildPlatform.Automatic) { if (environment.Platform.Is64Bit) { binPath = binPath.Combine("amd64"); } } if (buildPlatform == MSBuildPlatform.x64) { binPath = binPath.Combine("amd64"); } return(binPath); }
/// <summary> /// Sets the build platform to use when invoking MSBuild /// </summary> /// <param name="manager">The manager</param> /// <param name="platform">The <see cref="MSBuildPlatform"/> platform to build for</param> /// <returns>The updated manager</returns> public static ClickTwiceManager SetBuildPlatform(this ClickTwiceManager manager, MSBuildPlatform platform) { manager.Platform = platform == MSBuildPlatform.Automatic ? "AnyCPU" : platform.ToString(); return(manager); }