本文整理汇总了C#中MonoDevelop.Core.Assemblies.TargetRuntime.IsInstalled方法的典型用法代码示例。如果您正苦于以下问题:C# TargetRuntime.IsInstalled方法的具体用法?C# TargetRuntime.IsInstalled怎么用?C# TargetRuntime.IsInstalled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MonoDevelop.Core.Assemblies.TargetRuntime
的用法示例。
在下文中一共展示了TargetRuntime.IsInstalled方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetTargetFrameworkForAssembly
//FIXME: the fallback is broken since multiple frameworks can have the same corlib
public TargetFrameworkMoniker GetTargetFrameworkForAssembly (TargetRuntime tr, string file)
{
if (!File.Exists (file))
return TargetFrameworkMoniker.UNKNOWN;
var universe = CreateClosedUniverse ();
try {
IKVM.Reflection.Assembly assembly = universe.LoadFile (file);
var att = assembly.CustomAttributes.FirstOrDefault (a =>
a.AttributeType.FullName == "System.Runtime.Versioning.TargetFrameworkAttribute"
);
if (att != null) {
if (att.ConstructorArguments.Count == 1) {
var v = att.ConstructorArguments[0].Value as string;
TargetFrameworkMoniker m;
if (v != null && TargetFrameworkMoniker.TryParse (v, out m)) {
return m;
}
}
LoggingService.LogError ("Invalid TargetFrameworkAttribute in assembly {0}", file);
}
if (tr != null) {
foreach (var r in assembly.GetReferencedAssemblies ()) {
if (r.Name == "mscorlib") {
TargetFramework compatibleFramework = null;
// If there are several frameworks that can run the file, pick one that is installed
foreach (TargetFramework tf in GetKnownFrameworks ()) {
if (tf.GetCorlibVersion () == r.Version.ToString ()) {
compatibleFramework = tf;
if (tr.IsInstalled (tf))
return tf.Id;
}
}
if (compatibleFramework != null)
return compatibleFramework.Id;
break;
}
}
}
} catch (Exception ex) {
LoggingService.LogError ("Error determining target framework for assembly {0}: {1}", file, ex);
return TargetFrameworkMoniker.UNKNOWN;
} finally {
universe.Dispose ();
}
LoggingService.LogError ("Failed to determine target framework for assembly {0}", file);
return TargetFrameworkMoniker.UNKNOWN;
}
示例2: GetProjectBuilder
public static RemoteProjectBuilder GetProjectBuilder (TargetRuntime runtime, string toolsVersion, string file)
{
lock (builders) {
var toolsFx = Runtime.SystemAssemblyService.GetTargetFramework (new TargetFrameworkMoniker (toolsVersion));
string binDir = runtime.GetMSBuildBinPath (toolsFx);
if (!runtime.IsInstalled (toolsFx))
throw new InvalidOperationException (string.Format (
"Runtime '{0}' does not have the MSBuild '{1}' framework installed",
runtime.Id, toolsVersion));
string builderKey = runtime.Id + " " + toolsVersion;
RemoteBuildEngine builder;
if (builders.TryGetValue (builderKey, out builder)) {
builder.ReferenceCount++;
return new RemoteProjectBuilder (file, binDir, builder);
}
//always start the remote process explicitly, even if it's using the current runtime and fx
//else it won't pick up the assembly redirects from the builder exe
var exe = GetExeLocation (runtime, toolsVersion);
MonoDevelop.Core.Execution.RemotingService.RegisterRemotingChannel ();
var pinfo = new ProcessStartInfo (exe) {
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardError = true,
RedirectStandardInput = true,
};
runtime.GetToolsExecutionEnvironment (toolsFx).MergeTo (pinfo);
Process p = null;
try {
p = runtime.ExecuteAssembly (pinfo);
p.StandardInput.WriteLine (Process.GetCurrentProcess ().Id.ToString ());
string sref = p.StandardError.ReadLine ();
byte[] data = Convert.FromBase64String (sref);
MemoryStream ms = new MemoryStream (data);
BinaryFormatter bf = new BinaryFormatter ();
builder = new RemoteBuildEngine (p, (IBuildEngine) bf.Deserialize (ms));
} catch {
if (p != null) {
try {
p.Kill ();
} catch { }
}
throw;
}
builders [builderKey] = builder;
builder.ReferenceCount = 1;
return new RemoteProjectBuilder (file, binDir, builder);
}
}
示例3: GetProjectBuilder
public static RemoteProjectBuilder GetProjectBuilder (TargetRuntime runtime, string toolsVersion, string file)
{
lock (builders) {
var toolsFx = Runtime.SystemAssemblyService.GetTargetFramework (toolsVersion);
string binDir = runtime.GetMSBuildBinPath (toolsFx);
if (!runtime.IsInstalled (toolsFx))
throw new InvalidOperationException (string.Format (
"Runtime '{0}' cannot be used to build MSBuild '{1}' format projects",
runtime.Id, toolsVersion));
string builderKey = runtime.Id + " " + toolsVersion;
RemoteBuildEngine builder;
if (builders.TryGetValue (builderKey, out builder)) {
builder.ReferenceCount++;
return new RemoteProjectBuilder (file, binDir, builder);
}
if (runtime.IsRunning && toolsVersion == REFERENCED_MSBUILD_TOOLS) {
if (currentBuildEngine == null)
currentBuildEngine = new RemoteBuildEngine (null, new BuildEngine ());
return new RemoteProjectBuilder (file, binDir, currentBuildEngine);
}
else {
string exe = GetExeLocation (toolsVersion);
MonoDevelop.Core.Execution.RemotingService.RegisterRemotingChannel ();
ProcessStartInfo pinfo = new ProcessStartInfo (exe);
runtime.GetToolsExecutionEnvironment (toolsFx).MergeTo (pinfo);
pinfo.UseShellExecute = false;
pinfo.RedirectStandardError = true;
pinfo.RedirectStandardInput = true;
Process p = null;
try {
p = runtime.ExecuteAssembly (pinfo);
p.StandardInput.WriteLine (Process.GetCurrentProcess ().Id.ToString ());
string sref = p.StandardError.ReadLine ();
byte[] data = Convert.FromBase64String (sref);
MemoryStream ms = new MemoryStream (data);
BinaryFormatter bf = new BinaryFormatter ();
builder = new RemoteBuildEngine (p, (IBuildEngine) bf.Deserialize (ms));
} catch {
if (p != null) {
try {
p.Kill ();
} catch { }
}
throw;
}
}
builders [builderKey] = builder;
builder.ReferenceCount = 1;
return new RemoteProjectBuilder (file, binDir, builder);
}
}