public void VerifySdkResolverLoaderFileDiscoveryPattern() { var root = FileUtilities.GetTemporaryDirectory(); try { // Valid pattern is root\(Name)\(Name).dll. No other files should be considered. var d1 = Directory.CreateDirectory(Path.Combine(root, "Resolver1")); var d2 = Directory.CreateDirectory(Path.Combine(root, "NoResolver")); // Valid. var f1 = Path.Combine(d1.FullName, "Resolver1.dll"); // Invalid, won't be considered. var f2 = Path.Combine(d1.FullName, "Dependency.dll"); var f3 = Path.Combine(d2.FullName, "InvalidName.dll"); var f4 = Path.Combine(d2.FullName, "NoResolver.txt"); File.WriteAllText(f1, string.Empty); File.WriteAllText(f2, string.Empty); File.WriteAllText(f3, string.Empty); File.WriteAllText(f4, string.Empty); var strategy = new SdkResolverLoader(); var files = strategy.FindPotentialSdkResolvers(root); files.Count.ShouldBe(1); files[0].ShouldBe(f1); } finally { FileUtilities.DeleteDirectoryNoThrow(root, true); } }
public void SdkResolverLoaderPrefersManifestFile() { var root = FileUtilities.GetTemporaryDirectory(); try { var testFolder = Directory.CreateDirectory(Path.Combine(root, "MyTestResolver")); var wrongResolverDll = Path.Combine(testFolder.FullName, "MyTestResolver.dll"); var resolverManifest = Path.Combine(testFolder.FullName, "MyTestResolver.xml"); var assemblyToLoad = Path.Combine(root, "SomeOtherResolver.dll"); File.WriteAllText(wrongResolverDll, string.Empty); File.WriteAllText(assemblyToLoad, string.Empty); File.WriteAllText(resolverManifest, $@" <SdkResolver> <Path>{assemblyToLoad}</Path> </SdkResolver>"); SdkResolverLoader loader = new SdkResolverLoader(); var resolversFound = loader.FindPotentialSdkResolvers(root, new MockElementLocation("file")); resolversFound.Count.ShouldBe(1); resolversFound.First().ShouldBe(assemblyToLoad); } finally { FileUtilities.DeleteDirectoryNoThrow(root, true); } }
public void SdkResolverLoaderReadsManifestFileWithResolvableSdkPattern() { using (var env = TestEnvironment.Create(_output)) { var root = env.CreateFolder().Path; var resolverPath = Path.Combine(root, "MyTestResolver"); var resolverManifest = Path.Combine(resolverPath, "MyTestResolver.xml"); var assemblyToLoad = env.CreateFile(".dll").Path; Directory.CreateDirectory(resolverPath); File.WriteAllText(resolverManifest, $@" <SdkResolver> <ResolvableSdkPattern>1<.*</ResolvableSdkPattern> <Path>{assemblyToLoad}</Path> </SdkResolver>"); SdkResolverLoader loader = new SdkResolverLoader(); var resolversManifestsFound = loader.FindPotentialSdkResolversManifests(root, new MockElementLocation("file")); resolversManifestsFound.Count.ShouldBe(1); resolversManifestsFound.First().Path.ShouldBe(assemblyToLoad); resolversManifestsFound.First().ResolvableSdkRegex.ToString().ShouldBe("1<.*"); } }
public void AssertDefaultLoaderReturnsDefaultResolvers() { var loader = new SdkResolverLoader(); var resolvers = loader.LoadResolvers(_loggingContext, new MockElementLocation("file")); resolvers.Select(i => i.GetType()).ShouldBe(new [] { typeof(DefaultSdkResolver) }); }
public void AssertDefaultLoaderReturnsDefaultResolver() { var loader = new SdkResolverLoader(); var resolvers = loader.LoadResolvers(_loggingContext, new MockElementLocation("file")); Assert.Equal(1, resolvers.Count); Assert.Equal(typeof(DefaultSdkResolver), resolvers[0].GetType()); }
public void AssertDefaultLoaderReturnsDefaultResolvers() { var loader = new SdkResolverLoader(); var resolvers = loader.LoadResolvers(_loggingContext, new MockElementLocation("file")); resolvers.Select(i => i.GetType().FullName).ShouldBe(new [] { "NuGet.MSBuildSdkResolver.NuGetSdkResolver", typeof(DefaultSdkResolver).FullName }); _logger.ErrorCount.ShouldBe(0); _logger.WarningCount.ShouldBe(0); }
public void AssertDefaultLoaderReturnsDefaultResolver() { var loader = new SdkResolverLoader(); var log = new StringBuilder(); var logger = new MockLoggingService(message => log.AppendLine(message)); var bec = new BuildEventContext(0, 0, 0, 0, 0); var resolvers = loader.LoadResolvers(logger, bec, new MockElementLocation("file")); Assert.Equal(1, resolvers.Count); Assert.Equal(typeof(DefaultSdkResolver), resolvers[0].GetType()); }
public void SdkResolverLoaderErrorsWhenNoDllOrAssemblyFound() { using (var env = TestEnvironment.Create(_output)) { var root = env.CreateFolder().Path; var resolverPath = Path.Combine(root, "MyTestResolver"); Directory.CreateDirectory(resolverPath); SdkResolverLoader loader = new SdkResolverLoader(); var ex = Should.Throw <InvalidProjectFileException>(() => loader.FindPotentialSdkResolvers(root, new MockElementLocation("file"))); ex.ErrorCode.ShouldBe("MSB4246"); } }
public void SdkResolverLoaderErrorsWhenManifestTargetMissing() { using (var env = TestEnvironment.Create(_output)) { var root = env.CreateFolder().Path; var resolverPath = Path.Combine(root, "MyTestResolver"); var resolverManifest = Path.Combine(resolverPath, "MyTestResolver.xml"); // Note this does NOT create the file just gets a valid name var assemblyToLoad = env.GetTempFile(".dll").Path; Directory.CreateDirectory(resolverPath); File.WriteAllText(resolverManifest, $@" <SdkResolver> <Path>{assemblyToLoad}</Path> </SdkResolver>"); SdkResolverLoader loader = new SdkResolverLoader(); var ex = Should.Throw <InvalidProjectFileException>(() => loader.FindPotentialSdkResolvers(root, new MockElementLocation("file"))); ex.ErrorCode.ShouldBe("MSB4247"); } }
public void SdkResolverLoaderHonorsAdditionalResolversFolder() { using (var env = TestEnvironment.Create(_output)) { var origResolversFolder = Environment.GetEnvironmentVariable("MSBUILDADDITIONALSDKRESOLVERSFOLDER"); try { var testRoot = env.CreateFolder().Path; var additionalRoot = env.CreateFolder().Path; var resolver1 = "Resolver1"; var resolver1Path = Path.Combine(additionalRoot, resolver1, $"{resolver1}.dll"); Directory.CreateDirectory(Path.Combine(testRoot, resolver1)); File.WriteAllText(Path.Combine(testRoot, resolver1, $"{resolver1}.dll"), string.Empty); Directory.CreateDirectory(Path.Combine(additionalRoot, resolver1)); File.WriteAllText(resolver1Path, string.Empty); var resolver2 = "Resolver2"; var resolver2Path = Path.Combine(testRoot, resolver2, $"{resolver2}.dll"); Directory.CreateDirectory(Path.Combine(testRoot, resolver2)); File.WriteAllText(resolver2Path, string.Empty); var resolver3 = "Resolver3"; var resolver3Path = Path.Combine(additionalRoot, resolver3, $"{resolver3}.dll"); Directory.CreateDirectory(Path.Combine(additionalRoot, resolver3)); File.WriteAllText(resolver3Path, string.Empty); Environment.SetEnvironmentVariable("MSBUILDADDITIONALSDKRESOLVERSFOLDER", additionalRoot); SdkResolverLoader loader = new SdkResolverLoader(); IList <string> resolvers = loader.FindPotentialSdkResolvers(testRoot, new MockElementLocation("file")); resolvers.ShouldBeSameIgnoringOrder(new[] { resolver1Path, resolver2Path, resolver3Path }); } finally { Environment.SetEnvironmentVariable("MSBUILDADDITIONALSDKRESOLVERSFOLDER", origResolversFolder); } } }