public void GenerateClassWithAssemblyCheck() { try { var sinumerikOperateServicesAssembly = GlobalAssemblyCacheHelper.LoadAssembly(SinumerikOperateServicesName); var sinumerikOperateServicesWrapperAssembly = GlobalAssemblyCacheHelper.LoadAssembly(SinumerikOperateServicesWrapperName); var compilerParameters = new CompilerParameters(); compilerParameters.ReferencedAssemblies.Add(typeof(ISinumerikWrapper).Assembly.Location); compilerParameters.ReferencedAssemblies.Add(sinumerikOperateServicesAssembly.Location); compilerParameters.ReferencedAssemblies.Add(sinumerikOperateServicesWrapperAssembly.Location); compilerParameters.GenerateInMemory = true; var codeCompiler = CodeDomProvider.CreateProvider("CSharp"); var results = codeCompiler.CompileAssemblyFromEmbeddedSource(compilerParameters, this); results.WriteErrorsToConsole(); results.WriteOutputToConsole(); SinumerikWrapper = results.GetInstance <ISinumerikWrapper>(NamespaceName + "." + ClassName); if (SinumerikWrapper == null) { Console.WriteLine("SinumerikWrapper not created"); return; } Console.WriteLine("Created"); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public void ShouldThroughArgumentNullException() { FluentActions.Invoking(() => { GlobalAssemblyCacheHelper.GetLocation(null); }).Should().Throw <ArgumentNullException>(); }
public void GenerateClass() { try { var x = GlobalAssemblyCacheHelper.GetAssemblies(SinumerikOperateServicesName); var sinumerikOperateServicesAssembly = GlobalAssemblyCacheHelper.LoadAssembly(SinumerikOperateServicesName); var compilerParameters = new CompilerParameters(); compilerParameters.ReferencedAssemblies.Add(typeof(ISinumerikWrapper).Assembly.Location); compilerParameters.ReferencedAssemblies.Add(sinumerikOperateServicesAssembly.Location); compilerParameters.ReferencedAssemblies.Add(GlobalAssemblyCacheHelper.GetAssemblyLocation(SinumerikOperateServicesWrapperName)); compilerParameters.GenerateInMemory = true; compilerParameters.OutputAssembly = CompilerParametersOutputAssembly; compilerParameters.ConditionalIncludeDebugInformation(); var codeCompiler = CodeDomProvider.CreateProvider("CSharp"); var results = codeCompiler.CompileAssemblyFromEmbeddedSource(compilerParameters, this, sinumerikOperateServicesAssembly.GetName().Version); results.WriteErrorsToConsole(); results.WriteOutputToConsole(); Console.WriteLine(results.CompiledAssembly.FullName); SinumerikWrapper = results.GetInstance <ISinumerikWrapper>(NamespaceName + "." + ClassName); Console.WriteLine("SinumerikWrapper Created"); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public void TestMethod(string strongNameReference, string location) { string path = null; FluentActions.Invoking(() => { path = GlobalAssemblyCacheHelper.GetLocation(strongNameReference); }).Should().NotThrow(); path.Should().Be(location); }
public string ResolveAssemblyReference(string assemblyReference) { if (!string.IsNullOrWhiteSpace(assemblyReference)) { assemblyReference = this.ExpandAllVariables(assemblyReference); if (Path.IsPathRooted(assemblyReference)) { Zone zone = Zone.CreateFromUrl(new Uri(assemblyReference).AbsoluteUri); if ((zone.SecurityZone == SecurityZone.Trusted) || (zone.SecurityZone == SecurityZone.MyComputer)) { return(assemblyReference); } this.LogError(false, string.Format(CultureInfo.CurrentCulture, Microsoft.VisualStudio.TextTemplating.VSHost.Resources.AssemblyReferenceFailed, new object[] { string.Format(CultureInfo.CurrentCulture, Microsoft.VisualStudio.TextTemplating.VSHost.Resources.PathNotTrusted, new object[] { assemblyReference }) }), -1, -1, this.inputFile); return(string.Empty); } string location = GlobalAssemblyCacheHelper.GetLocation(assemblyReference); if (!string.IsNullOrEmpty(location)) { return(location); } OrchestratorPackage singleton = OrchestratorPackage.Singleton; if (singleton != null) { string vSInstallDir = GetVSInstallDir(singleton.ApplicationRegistryRoot); if (!string.IsNullOrEmpty(vSInstallDir)) { location = Path.Combine(Path.Combine(vSInstallDir, "PublicAssemblies"), assemblyReference); if (File.Exists(location)) { return(location); } } } IVsExtensionManager service = this.serviceProvider.GetService(typeof(SVsExtensionManager)) as IVsExtensionManager; if (service != null) { location = this.ResolveAssemblyReferenceViaExtensionManager(assemblyReference, service); if (!string.IsNullOrEmpty(location)) { return(location); } } } return(assemblyReference); }
private static void Main(string[] args) { var x = GlobalAssemblyCacheHelper.GetAssemblyNames("Siemens.Sinumerik.Operate.Services"); var a = GlobalAssemblyCacheHelper.GetAssemblies("Siemens.Sinumerik.Operate.Services"); var list = new List <string>(); foreach (var y in a) { if (GlobalAssemblyCacheHelper.TryGetAssemblyLocation(y, out var i)) { list.Add(i); } } foreach (var assemblyName in GlobalAssemblyCacheHelper.GetAssemblies()) { Console.WriteLine(assemblyName); } }
public void GenerateClass() { try { // var source = CreateSource(); // var source = this.LoadEmbeddedSource("SinumerikWrapper.cs"); ////var sources = this.LoadEmbeddedSources(); ////Console.WriteLine(sources); //Classic CodeDOM var codeCompiler = CodeDomProvider.CreateProvider("CSharp"); ////Roslyn CodeDOM //var provOptions = new Dictionary<string, string> //{ // {"CompilerVersion", "v3.5"} //}; //var codeCompiler = new CSharpCodeProvider(provOptions); Console.WriteLine($"Assembly name: {SinumerikOperateServicesName}"); var sinumerikOperateServicesAssembly = GlobalAssemblyCacheHelper.LoadAssembly(SinumerikOperateServicesName); if (sinumerikOperateServicesAssembly == null) { Console.WriteLine("assembly not Loaded"); return; } { var name = sinumerikOperateServicesAssembly.GetName().FullName; Console.WriteLine("Name: " + name); var version = sinumerikOperateServicesAssembly.GetName().Version; Console.WriteLine("Version: " + version); } Console.WriteLine($"Assembly name: {SinumerikOperateServicesWrapperName}"); var sinumerikOperateServicesWrapperAssembly = GlobalAssemblyCacheHelper.LoadAssembly(SinumerikOperateServicesWrapperName); if (sinumerikOperateServicesWrapperAssembly == null) { Console.WriteLine("assembly not Loaded"); return; } { var name = sinumerikOperateServicesWrapperAssembly.GetName().FullName; Console.WriteLine("Name: " + name); var version = sinumerikOperateServicesWrapperAssembly.GetName().Version; Console.WriteLine("Version: " + version); } var compilerParameters = new CompilerParameters(); compilerParameters.ReferencedAssemblies.Add(typeof(ISinumerikWrapper).Assembly.Location); compilerParameters.ReferencedAssemblies.Add(sinumerikOperateServicesAssembly.Location); compilerParameters.ReferencedAssemblies.Add(sinumerikOperateServicesWrapperAssembly.Location); compilerParameters.GenerateInMemory = true; Console.WriteLine("Compile assembly"); // var results = codeCompiler.CompileAssemblyFromSource(compilerParameters, sources.ToArray()); var results = codeCompiler.CompileAssemblyFromEmbeddedSource(compilerParameters, this); results.WriteErrorsToConsole(); results.WriteOutputToConsole(); SinumerikWrapper = results.GetInstance <ISinumerikWrapper>(NamespaceName + "." + ClassName); if (SinumerikWrapper == null) { Console.WriteLine("SinumerikWrapper not created"); return; } Console.WriteLine("Created"); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public void CanIdentifyStrongName() { string name = "SubSonic.Core, Version=1.1.0.0, Culture=neutral, PublicKeyToken=abcD0E9fghj"; GlobalAssemblyCacheHelper.IsStrongName(name).Should().BeTrue(); }