public void UnavailableEnvironments() { var collection = new Microsoft.Build.Evaluation.ProjectCollection(); try { var service = new MockInterpreterOptionsService(); var proj = collection.LoadProject(TestData.GetPath(@"TestData\Environments\Unavailable.pyproj")); using (var provider = new MSBuildProjectInterpreterFactoryProvider(service, proj)) { try { provider.DiscoverInterpreters(); Assert.Fail("Expected InvalidDataException in DiscoverInterpreters"); } catch (InvalidDataException ex) { AssertUtil.AreEqual(ex.Message .Replace(TestData.GetPath("TestData\\Environments\\"), "$") .Split('\r', '\n') .Where(s => !string.IsNullOrEmpty(s)) .Select(s => s.Trim()), "Some project interpreters failed to load:", @"Interpreter $env\ has invalid value for 'Id': INVALID ID", @"Interpreter $env\ has invalid value for 'Version': INVALID VERSION", @"Base interpreter $env\ has invalid value for 'BaseInterpreter': INVALID BASE", @"Interpreter $env\ has invalid value for 'InterpreterPath': INVALID<>PATH", @"Interpreter $env\ has invalid value for 'WindowsInterpreterPath': INVALID<>PATH", @"Interpreter $env\ has invalid value for 'LibraryPath': INVALID<>PATH", @"Base interpreter $env\ has invalid value for 'BaseInterpreter': {98512745-4ac7-4abb-9f33-120af32edc77}" ); } var factories = provider.GetInterpreterFactories().ToList(); foreach (var fact in factories) { Console.WriteLine("{0}: {1}", fact.GetType().FullName, fact.Description); } foreach (var fact in factories) { Assert.IsInstanceOfType( fact, typeof(MSBuildProjectInterpreterFactoryProvider.NotFoundInterpreterFactory), string.Format("{0} was not correct type", fact.Description) ); Assert.IsFalse(provider.IsAvailable(fact), string.Format("{0} was not unavailable", fact.Description)); } AssertUtil.AreEqual(factories.Select(f => f.Description), "Invalid BaseInterpreter (unavailable)", "Invalid InterpreterPath (unavailable)", "Invalid WindowsInterpreterPath (unavailable)", "Invalid LibraryPath (unavailable)", "Absent BaseInterpreter (unavailable)", "Unknown Python 2.7" ); } } finally { collection.UnloadAllProjects(); collection.Dispose(); } }
public void UnavailableEnvironments() { var collection = new Microsoft.Build.Evaluation.ProjectCollection(); try { var service = new MockInterpreterOptionsService(); var proj = collection.LoadProject(TestData.GetPath(@"TestData\Environments\Unavailable.pyproj")); var contextProvider = new MockProjectContextProvider(proj); var logger = new MockLogger(); using (var provider = new MSBuildProjectInterpreterFactoryProvider( new[] { new Lazy <IProjectContextProvider>(() => contextProvider) }, null, new[] { new Lazy <IInterpreterLog>(() => logger) })) { var configs = provider.GetInterpreterConfigurations().ToArray(); // force the load... AssertUtil.AreEqual( logger.Errors.ToString() .Replace(TestData.GetPath("TestData\\Environments\\"), "$") .Split('\r', '\n') .Where(s => !string.IsNullOrEmpty(s)) .Select(s => s.Trim()), @"Interpreter $env\ has invalid value for 'Id':", @"Interpreter $env\ has invalid value for 'Version': INVALID VERSION", @"Interpreter $env\ has invalid value for 'InterpreterPath': INVALID<>PATH", @"Interpreter $env\ has invalid value for 'WindowsInterpreterPath': INVALID<>PATH" ); var factories = provider.GetInterpreterFactories().ToList(); foreach (var fact in factories) { Console.WriteLine("{0}: {1}", fact.GetType().FullName, fact.Configuration.Description); } foreach (var fact in factories) { Assert.IsInstanceOfType( fact, typeof(NotFoundInterpreterFactory), string.Format("{0} was not correct type", fact.Configuration.Description) ); Assert.IsFalse(fact.Configuration.IsAvailable(), string.Format("{0} was not unavailable", fact.Configuration.Description)); } AssertUtil.AreEqual(factories.Select(f => f.Configuration.Description), "Invalid InterpreterPath (unavailable)", "Invalid WindowsInterpreterPath (unavailable)" ); } } finally { collection.UnloadAllProjects(); collection.Dispose(); } }
public void EndBatchBuild() { if (!_batchBuildStarted) { throw new InvalidOperationException(); } MSB.Execution.BuildManager.DefaultBuildManager.EndBuild(); // unload project so collection will release global strings _batchBuildProjectCollection?.UnloadAllProjects(); _batchBuildProjectCollection = null; _batchBuildLogger = null; _batchBuildStarted = false; }
public Task <(MSB.Evaluation.Project?project, DiagnosticLog log)> LoadProjectAsync( string path, CancellationToken cancellationToken) { if (_batchBuildStarted) { return(LoadProjectAsync(path, _batchBuildProjectCollection, cancellationToken)); } else { var projectCollection = new MSB.Evaluation.ProjectCollection(AllGlobalProperties); try { return(LoadProjectAsync(path, projectCollection, cancellationToken)); } finally { // unload project so collection will release global strings projectCollection.UnloadAllProjects(); } } }
public void UnavailableEnvironments() { var collection = new Microsoft.Build.Evaluation.ProjectCollection(); try { var service = new MockInterpreterOptionsService(); var proj = collection.LoadProject(TestData.GetPath(@"TestData\Environments\Unavailable.pyproj")); using (var provider = new MSBuildProjectInterpreterFactoryProvider(service, proj)) { try { provider.DiscoverInterpreters(); Assert.Fail("Expected InvalidDataException in DiscoverInterpreters"); } catch (InvalidDataException ex) { AssertUtil.AreEqual(ex.Message .Replace(TestData.GetPath("TestData\\Environments\\"), "$") .Split('\r', '\n') .Where(s => !string.IsNullOrEmpty(s)) .Select(s => s.Trim()), "Some project interpreters failed to load:", @"Interpreter $env\ has invalid value for 'Id': INVALID ID", @"Interpreter $env\ has invalid value for 'Version': INVALID VERSION", @"Interpreter $env\ has invalid value for 'BaseInterpreter': INVALID BASE", @"Interpreter $env\ has invalid value for 'InterpreterPath': INVALID<>PATH", @"Interpreter $env\ has invalid value for 'WindowsInterpreterPath': INVALID<>PATH", @"Interpreter $env\ has invalid value for 'LibraryPath': INVALID<>PATH", @"Interpreter $env\ has invalid value for 'BaseInterpreter': {98512745-4ac7-4abb-9f33-120af32edc77}" ); } var factories = provider.GetInterpreterFactories().ToList(); foreach (var fact in factories) { Console.WriteLine("{0}: {1}", fact.GetType().FullName, fact.Description); } foreach (var fact in factories) { Assert.IsInstanceOfType( fact, typeof(MSBuildProjectInterpreterFactoryProvider.NotFoundInterpreterFactory), string.Format("{0} was not correct type", fact.Description) ); Assert.IsFalse(provider.IsAvailable(fact), string.Format("{0} was not unavailable", fact.Description)); } AssertUtil.AreEqual(factories.Select(f => f.Description), "Invalid BaseInterpreter (unavailable)", "Invalid InterpreterPath (unavailable)", "Invalid WindowsInterpreterPath (unavailable)", "Invalid LibraryPath (unavailable)", "Absent BaseInterpreter (unavailable)", "Unknown Python 2.7" ); } } finally { collection.UnloadAllProjects(); collection.Dispose(); } }
public void UnavailableEnvironments() { var collection = new Microsoft.Build.Evaluation.ProjectCollection(); try { var service = new MockInterpreterOptionsService(); var proj = collection.LoadProject(TestData.GetPath(@"TestData\Environments\Unavailable.pyproj")); var contextProvider = new MockProjectContextProvider(proj); var logger = new MockLogger(); using (var provider = new MSBuildProjectInterpreterFactoryProvider( new[] { new Lazy<IProjectContextProvider>(() => contextProvider) }, null, new[] { new Lazy<IInterpreterLog>(() => logger) })) { var configs = provider.GetInterpreterConfigurations().ToArray(); // force the load... AssertUtil.AreEqual( logger.Errors.ToString() .Replace(TestData.GetPath("TestData\\Environments\\"), "$") .Split('\r', '\n') .Where(s => !string.IsNullOrEmpty(s)) .Select(s => s.Trim()), @"Interpreter $env\ has invalid value for 'Id':", @"Interpreter $env\ has invalid value for 'Version': INVALID VERSION", @"Interpreter $env\ has invalid value for 'InterpreterPath': INVALID<>PATH", @"Interpreter $env\ has invalid value for 'WindowsInterpreterPath': INVALID<>PATH" ); var factories = provider.GetInterpreterFactories().ToList(); foreach (var fact in factories) { Console.WriteLine("{0}: {1}", fact.GetType().FullName, fact.Configuration.Description); } foreach (var fact in factories) { Assert.IsInstanceOfType( fact, typeof(NotFoundInterpreterFactory), string.Format("{0} was not correct type", fact.Configuration.Description) ); Assert.IsFalse(fact.Configuration.IsAvailable(), string.Format("{0} was not unavailable", fact.Configuration.Description)); } AssertUtil.AreEqual(factories.Select(f => f.Configuration.Description), "Invalid InterpreterPath (unavailable)", "Invalid WindowsInterpreterPath (unavailable)" ); } } finally { collection.UnloadAllProjects(); collection.Dispose(); } }