Esempio n. 1
0
 private static void CheckMSBuildToolset()
 {
     // Check that we can create a project
     using (var projectCollection = new Microsoft.Build.Evaluation.ProjectCollection())
     {
         if (projectCollection.GetToolset("15.0") == null && // VS 2017
             projectCollection.GetToolset("Current") == null)    // VS 2019+ (https://github.com/Microsoft/msbuild/issues/3778)
         {
             throw new InvalidOperationException("Could not find a supported MSBuild toolset version (expected 15.0 or later)");
         }
     }
 }
Esempio n. 2
0
        /// <summary>
        /// This method finds a compatible version of MSBuild and set environment variables so that Microsoft classes can asset it.
        /// It is needed since Microsoft regression introduced in VS15.2. Hopefully this code can be removed in the future.
        /// </summary>
        public static bool FindAndSetMSBuildVersion()
        {
            // Find a compatible version of MSBuild with the required workloads
            var buildTools = VisualStudioVersions.AvailableBuildTools
                             .Where(x => x.Version >= new Version("15.0")).OrderByDescending(x => x.Version)
                             .FirstOrDefault(x =>
            {
                // FIXME: factorize with SiliconStudio.Xenko.PackageInstall.Program
                // FIXME: ideally prompt to install the missing prerequisites
                if (x.PackageVersions.ContainsKey("Microsoft.VisualStudio.Workload.ManagedDesktop"))
                {
                    return(true);
                }
                if (x.PackageVersions.ContainsKey("Microsoft.VisualStudio.Workload.MSBuildTools") && x.PackageVersions.ContainsKey("Microsoft.Net.Component.4.6.1.TargetingPack"))
                {
                    return(true);
                }
                return(false);
            });

            if (buildTools != null)
            {
                Environment.SetEnvironmentVariable("VSINSTALLDIR", buildTools.InstallationPath);
                Environment.SetEnvironmentVariable("VisualStudioVersion", @"15.0");
            }
            // Check that we can create a project
            var projectCollection = new Microsoft.Build.Evaluation.ProjectCollection();

            return(projectCollection.GetToolset("15.0") != null);
        }
 private static void CheckMSBuildToolset()
 {
     // Check that we can create a project
     using (var projectCollection = new Microsoft.Build.Evaluation.ProjectCollection())
     {
         if (projectCollection.GetToolset("15.0") == null)
         {
             throw new InvalidOperationException("Could not find MSBuild toolset 15.0");
         }
     }
 }
Esempio n. 4
0
 private static bool CheckMSBuildToolset()
 {
     // Check that we can create a project
     try
     {
         using (var projectCollection = new Microsoft.Build.Evaluation.ProjectCollection())
         {
             return(projectCollection.GetToolset("15.0") != null);
         }
     }
     catch
     {
         return(false);
     }
 }