public void SetUp() { project = new MockCSharpProject(); project.FileName = @"C:\Projects\MyTests\MyTests.csproj"; project.AssemblyName = "MyTests"; project.OutputType = OutputType.Library; project.SetProperty("OutputPath", null); }
public void SetUp() { project = new MockCSharpProject(); project.FileName = @"C:\Projects\MyTests\MyTests.csproj"; project.AssemblyName = "MyTests"; project.OutputType = OutputType.Library; helper = new UnitTestApplicationStartHelper(); }
internal static string BuildMyNamespaceCode(CompilableProject vbProject) { string ns; if (string.IsNullOrEmpty(vbProject.RootNamespace)) ns = "My"; else ns = vbProject.RootNamespace + ".My"; string projectType; if (vbProject.OutputType == OutputType.WinExe) projectType = "WindowsApplication"; else if (vbProject.OutputType == OutputType.Exe) projectType = "ConsoleApplication"; else projectType = "Library"; StringBuilder output = new StringBuilder(); bool outputActive = true; using (StreamReader r = new StreamReader(OpenResource())) { string line; while ((line = r.ReadLine()) != null) { string trimmedLine = line.Trim(); if (trimmedLine == "#endif") { outputActive = true; continue; } if (!outputActive) { continue; } if (trimmedLine == "/*LIST OF FORMS*/") { var compilation = SD.ParserService.GetCompilation(vbProject); ITypeDefinition myFormsClass = FindMyFormsClass(compilation.MainAssembly, ns); if (myFormsClass != null) { string indentation = line.Substring(0, line.Length - trimmedLine.Length); foreach (IProperty p in myFormsClass.Properties) { string typeName = "global::" + p.ReturnType.FullName; output.AppendLine(indentation + typeName + " " + p.Name + "_instance;"); output.AppendLine(indentation + "bool " + p.Name + "_isCreating;"); output.AppendLine(indentation + "public " + typeName + " " + p.Name + " {"); output.AppendLine(indentation + "\t[DebuggerStepThrough] get { return GetForm(ref " + p.Name + "_instance, ref " + p.Name + "_isCreating); }"); output.AppendLine(indentation + "\t[DebuggerStepThrough] set { SetForm(ref " + p.Name + "_instance, value); }"); output.AppendLine(indentation + "}"); output.AppendLine(indentation); } } } else if (trimmedLine.StartsWith("#if ", StringComparison.Ordinal)) { outputActive = trimmedLine.Substring(4) == projectType; } else { output.AppendLine(StringParser.Parse(line.Replace("MyNamespace", ns))); } } } return output.ToString(); }
public static string ConvertTypeName(Type type, string fileName, CompilableProject project = null) { Version version; if (project == null) version = GetTargetFrameworkVersionFrom(fileName); else version = ScanVersion(project.TargetFrameworkVersion); string name = type.AssemblyQualifiedName; if (type.Assembly.GlobalAssemblyCache && IsFrameworkAssembly(type.Assembly.GetName().GetPublicKeyToken())) name = type.AssemblyQualifiedName.Replace(", Version=4.0.0.0,", ", Version=" + PrintVersion(version) + ","); return name; }
/// <summary> /// Update all .resx in a project. /// </summary> public static void UpdateResourceFiles(CompilableProject project) { foreach (var resXFile in project.Items.OfType<FileProjectItem>().Where(f => ".resx".Equals(Path.GetExtension(f.FileName), StringComparison.OrdinalIgnoreCase))) { using (var buffer = new MemoryStream()) { using (var reader = new ResXResourceReader(resXFile.FileName) { UseResXDataNodes = true }) using (var writer = new ResXResourceWriter(buffer, t => ConvertTypeName(t, resXFile.FileName, project))) { foreach (DictionaryEntry entry in reader) { writer.AddResource(entry.Key.ToString(), entry.Value); } } File.WriteAllBytes(resXFile.FileName, buffer.ToArray()); } } }
/// <summary> /// Update all .resx in a project. /// </summary> public static void UpdateResourceFiles(CompilableProject project) { foreach (var resXFile in project.Items.OfType <FileProjectItem>().Where(f => ".resx".Equals(Path.GetExtension(f.FileName), StringComparison.OrdinalIgnoreCase))) { using (var buffer = new MemoryStream()) { using (var reader = new ResXResourceReader(resXFile.FileName) { UseResXDataNodes = true }) using (var writer = new ResXResourceWriter(buffer, t => ConvertTypeName(t, resXFile.FileName, project))) { foreach (DictionaryEntry entry in reader) { writer.AddResource(entry.Key.ToString(), entry.Value); } } File.WriteAllBytes(resXFile.FileName, buffer.ToArray()); } } }
void UpdateAppConfig(TargetFramework newFramework) { // When changing the target framework, update any existing app.config // Also, for applications (not libraries), create an app.config is it is required for the target framework bool createAppConfig = newFramework.RequiresAppConfigEntry && (Project.OutputType != OutputType.Library && Project.OutputType != OutputType.Module); string appConfigFileName = CompilableProject.GetAppConfigFile(Project, createAppConfig); if (appConfigFileName == null) { return; } using (FakeXmlViewContent xml = new FakeXmlViewContent(appConfigFileName)) { if (xml.Document != null) { XElement configuration = xml.Document.Root; XElement startup = configuration.Element("startup"); if (startup == null) { startup = new XElement("startup"); if (configuration.HasElements && configuration.Elements().First().Name == "configSections") { // <configSections> must be first element configuration.Elements().First().AddAfterSelf(startup); } else { startup = configuration.AddFirstWithIndentation(startup); } } XElement supportedRuntime = startup.Element("supportedRuntime"); if (supportedRuntime == null) { supportedRuntime = startup.AddFirstWithIndentation(new XElement("supportedRuntime")); } supportedRuntime.SetAttributeValue("version", newFramework.SupportedRuntimeVersion); supportedRuntime.SetAttributeValue("sku", newFramework.SupportedSku); } } }
public static string ConvertTypeName(Type type, string fileName, CompilableProject project = null) { Version version; if (project == null) { version = GetTargetFrameworkVersionFrom(fileName); } else { version = ScanVersion(project.TargetFrameworkVersion); } string name = type.AssemblyQualifiedName; if (type.Assembly.GlobalAssemblyCache && IsFrameworkAssembly(type.Assembly.GetName().GetPublicKeyToken())) { name = type.AssemblyQualifiedName.Replace(", Version=4.0.0.0,", ", Version=" + PrintVersion(version) + ","); } return(name); }
public DotNetStartBehavior(CompilableProject project, ProjectBehavior next = null) : base(project, next) { }
bool CheckWebProjectStartInfo(CompilableProject project, WebProjectOptions options) { if (project == null) { MessageService.ShowError("${res:ICSharpCode.WepProjectOptionsPanel.NoStartupProject}"); return false; } if (options == null || options.Data == null) { MessageService.ShowError("${res:ICSharpCode.WepProjectOptionsPanel.NoProjectUrlOrProgramAction}"); return false; } return true; }
static Compiler.CompilerParameters GetParameters(CompilableProject project) { Compiler.CompilerParameters p = new Compiler.CompilerParameters(); var items = project.GetItemsOfType(ItemType.Reference) .OfType<ReferenceProjectItem>() .Select(item => item.FileName) .Concat( project.GetItemsOfType(ItemType.ProjectReference) .OfType<ProjectReferenceProjectItem>() .Select(item => item.ReferencedProject.OutputAssemblyFullPath) ); TargetFramework tf = project.CurrentTargetFramework; if (tf == null) throw new InvalidOperationException(); p.CompilerOptions = "/nostdlib /unsafe"; p.GenerateInMemory = true; p.ReferencedAssemblies.AddRange(items.ToArray()); string mscorlib = GetMscorlibPath(tf); if (mscorlib != null) p.ReferencedAssemblies.Add(mscorlib); if (IsGreaterThan(Util.TargetDotNetFrameworkVersion.Version35, VersionForString(tf.Name)) && !p.ReferencedAssemblies.OfType<string>().Any(s => s.Contains("System.Core.dll"))) p.ReferencedAssemblies.Add("System.Core.dll"); return p; }