Пример #1
0
		protected CompilableProject(ProjectCreateInformation information)
			: base(information)
		{
			this.OutputType = OutputType.Exe;
			SetProperty("RootNamespace", information.RootNamespace);
			SetProperty("AssemblyName", information.ProjectName);
			
			if (information.TargetFramework != null) {
				SetProperty(null, null, "TargetFrameworkVersion", information.TargetFramework.TargetFrameworkVersion, PropertyStorageLocations.Base, true);
				if (!string.IsNullOrEmpty(information.TargetFramework.TargetFrameworkProfile)) {
					SetProperty(null, null, "TargetFrameworkProfile", information.TargetFramework.TargetFrameworkProfile, PropertyStorageLocations.Base, true);
				}
			}
			
			SetProperty("Debug", null, "OutputPath", @"bin\Debug\",
			            PropertyStorageLocations.ConfigurationSpecific, true);
			SetProperty("Release", null, "OutputPath", @"bin\Release\",
			            PropertyStorageLocations.ConfigurationSpecific, true);
			LoadConfigurationPlatformNamesFromMSBuild();
			
			SetProperty("Debug", null, "DebugSymbols", "True",
			            PropertyStorageLocations.ConfigurationSpecific, true);
			SetProperty("Release", null, "DebugSymbols", "False",
			            PropertyStorageLocations.ConfigurationSpecific, true);
			
			SetProperty("Debug", null, "DebugType", "Full",
			            PropertyStorageLocations.ConfigurationSpecific, true);
			SetProperty("Release", null, "DebugType", "None",
			            PropertyStorageLocations.ConfigurationSpecific, true);
			
			SetProperty("Debug", null, "Optimize", "False",
			            PropertyStorageLocations.ConfigurationSpecific, true);
			SetProperty("Release", null, "Optimize", "True",
			            PropertyStorageLocations.ConfigurationSpecific, true);
		}
		public void SetUpFixture()
		{
			SD.InitializeForUnitTests();
			WixBindingTestsHelper.InitMSBuildEngine();
			
			// create the project.
			ProjectCreateInformation info = new ProjectCreateInformation(MockSolution.Create(), new FileName(@"C:\Projects\Test\Test.wixproj"));

			wixProject = new WixProjectWithOverriddenSave(info);
			
			// Add wix extensionitem.
			wixExtensionItem = new WixExtensionProjectItem(wixProject);
			wixExtensionItem.Include = @"..\..\first.dll";
			ProjectService.AddProjectItem(wixProject, wixExtensionItem);
			
			// Run Initialize on the WixExtensionFolderNode, which is 
			// equivalent to expanding the node, so it adds it children. Cannot
			// call ExtTreeNode.Expanding since this relies on the tree node
			// being visible.
			WixExtensionFolderNodeTester nodeTester = new WixExtensionFolderNodeTester(wixProject);
			nodeTester.RunInitialize();
			
			wixExtensionFolderNode = (WixExtensionFolderNode)nodeTester;
			wixExtensionNode = (WixExtensionNode)wixExtensionFolderNode.Nodes[0];
		}
Пример #3
0
		public WixProject(ProjectCreateInformation info)
			: base(info)
		{
			SetProperty("OutputType", "Package");
			AddWixTargetsPathProperties();
			AddImport(DefaultTargetsFile, null);
			CheckWixIsInstalled();
		}
		public void SetUpFixture()
		{
			SD.InitializeForUnitTests();
			WixBindingTestsHelper.InitMSBuildEngine();
			
			info = new ProjectCreateInformation(MockSolution.Create(), new FileName(@"C:\Projects\Test\Test.wixproj"));
			info.RootNamespace = "Test";

			project = new WixProject(info);
		}
Пример #5
0
		public static TestableProject CreateTestProject(
			ISolution parentSolution,
			string name,
			string fileName = null)
		{
			var createInfo = new ProjectCreateInformation(parentSolution, new FileName(fileName ?? (@"d:\projects\Test\TestProject\" + name + ".csproj")));
			
			var project = new TestableProject(createInfo);
			((ICollection<IProject>)parentSolution.Projects).Add(project);
			return project;
		}
		/// <summary>
		/// Creates a WixProject that contains no WixObject or WixLibrary items.
		/// </summary>
		public static WixProject CreateEmptyWixProject()
		{
			// Make sure the MSBuildEngine is initialised correctly.
			InitMSBuildEngine();
			
			// create the project.
			ProjectCreateInformation info = new ProjectCreateInformation(MockRepository.GenerateStub<ISolution>(), new FileName(@"C:\Projects\Test\Test.wixproj"));
			info.Solution.Stub(s => s.MSBuildProjectCollection).Return(new ProjectCollection());
			info.ProjectName = "Test";

			return new DummyWixProject(info);
		}
Пример #7
0
		public CppProject(ProjectCreateInformation info)
			: base(info)
		{
			try {
				AddImport(DefaultPropsFile, null);
				AddImport(PropsFile, null);
				AddImport(DefaultTargetsFile, null);
				AddProjectConfigurationsItemGroup();
				base.ReevaluateIfNecessary(); // provoke exception if import is invalid
			} catch (InvalidProjectFileException ex) {
				Dispose();
				throw new ProjectLoadException("Please ensure that the Windows SDK is installed on your computer.\n\n" + ex.Message, ex);
			}
		}
Пример #8
0
		public CSharpProject(ProjectCreateInformation info)
			: base(info)
		{
			Init();
			
			this.AddImport(DefaultTargetsFile, null);
			
			SetProperty("Debug", null, "CheckForOverflowUnderflow", "True",
			            PropertyStorageLocations.ConfigurationSpecific, true);
			SetProperty("Release", null, "CheckForOverflowUnderflow", "False",
			            PropertyStorageLocations.ConfigurationSpecific, true);
			
			SetProperty("Debug", null, "DefineConstants", "DEBUG;TRACE",
			            PropertyStorageLocations.ConfigurationSpecific, false);
			SetProperty("Release", null, "DefineConstants", "TRACE",
			            PropertyStorageLocations.ConfigurationSpecific, false);
			
			if (info.InitializeTypeSystem)
				InitializeProjectContent(new CSharpProjectContent());
		}
Пример #9
0
		protected CompilableProject(ProjectCreateInformation information)
			: base(information)
		{
			this.OutputType = OutputType.Exe;
			this.RootNamespace = information.RootNamespace;
			this.AssemblyName = information.ProjectName;
			
			ClientProfileTargetFramework clientProfile = information.TargetFramework as ClientProfileTargetFramework;
			if (clientProfile != null) {
				SetProperty(null, null, "TargetFrameworkVersion", clientProfile.FullFramework.Name, PropertyStorageLocations.Base, true);
				SetProperty(null, null, "TargetFrameworkProfile", "Client", PropertyStorageLocations.Base, true);
			} else if (information.TargetFramework != null) {
				SetProperty(null, null, "TargetFrameworkVersion", information.TargetFramework.Name, PropertyStorageLocations.Base, true);
			}
			
			SetProperty("Debug", null, "OutputPath", @"bin\Debug\",
			            PropertyStorageLocations.ConfigurationSpecific, true);
			SetProperty("Release", null, "OutputPath", @"bin\Release\",
			            PropertyStorageLocations.ConfigurationSpecific, true);
			LoadConfigurationPlatformNamesFromMSBuild();
			
			SetProperty("Debug", null, "DebugSymbols", "True",
			            PropertyStorageLocations.ConfigurationSpecific, true);
			SetProperty("Release", null, "DebugSymbols", "False",
			            PropertyStorageLocations.ConfigurationSpecific, true);
			
			SetProperty("Debug", null, "DebugType", "Full",
			            PropertyStorageLocations.ConfigurationSpecific, true);
			SetProperty("Release", null, "DebugType", "None",
			            PropertyStorageLocations.ConfigurationSpecific, true);
			
			SetProperty("Debug", null, "Optimize", "False",
			            PropertyStorageLocations.ConfigurationSpecific, true);
			SetProperty("Release", null, "Optimize", "True",
			            PropertyStorageLocations.ConfigurationSpecific, true);
		}
			public DummyWixProject(ProjectCreateInformation info) : base (info)
			{
			}
Пример #11
0
		public static MSBuildBasedProject CreateCSharpProject()
		{
			var createInfo = new ProjectCreateInformation(FakeSolution.Create(), new FileName(@"d:\projects\MyProject\MyProject.csproj"));
			return new MSBuildBasedProject(createInfo);
		}
Пример #12
0
		public TestableProject(ProjectCreateInformation createInfo)
			: base(createInfo)
		{
		}
Пример #13
0
		public IProject CreateProject(ProjectCreateInformation info)
		{
			return new WixProject(info);
		}
Пример #14
0
		public IProject CreateProject(ProjectCreateInformation info) {
			info.ActiveProjectConfiguration = new ConfigurationAndPlatform("Debug", "Win32");
			return new CppProject(info);
		}
Пример #15
0
		void RunPreCreateActions(ProjectCreateInformation projectCreateInformation)
		{
			foreach (var action in preCreateActions) {
				action(projectCreateInformation);
			}
		}
Пример #16
0
 IProject IProjectBinding.CreateProject(ProjectCreateInformation info)
 {
     // TODO: VBP creation currently not supported.
     throw new NotSupportedException("VBP creation is currently not supported.");
 }
		public WixProjectWithOverriddenSave(ProjectCreateInformation info) : base(info)
		{
		}
Пример #18
0
		public static TestableProject CreateProject(string fileName, string projectName)
		{
			var createInfo = new ProjectCreateInformation(FakeSolution.Create(), new FileName(fileName));
			createInfo.ProjectName = projectName;
			return new TestableProject(createInfo);
		}
Пример #19
0
		public static TestableProject CreateProject()
		{
			var info = new ProjectCreateInformation(MockRepository.GenerateStub<ISolution>(), FileName.Create(@"d:\projects\MyProject\MyProject.csproj"));
			info.Solution.Stub(s => s.MSBuildProjectCollection).Return(new ProjectCollection());
			return new TestableProject(info);
		}
Пример #20
0
 public TestableProject(ProjectCreateInformation info)
     : base(info)
 {
     rootNamespace = info.ProjectName;
 }
 public IProject CreateProject(ProjectCreateInformation info)
 {
     return null;
 }
Пример #22
0
		public IProject CreateProject(ProjectCreateInformation info)
		{
			throw new NotImplementedException();
		}
Пример #23
0
		//Show prompt, create files from template, create project, execute command, save project
		public bool CreateProject(ProjectTemplateResult templateResults, string defaultLanguage, ISolutionFolder target)
		{
			var projectCreateOptions = templateResults.Options;
			var parentSolution = templateResults.Options.Solution;
			IProject project = null;
			bool success = false;
			try
			{
				string language = string.IsNullOrEmpty(languageName) ? defaultLanguage : languageName;
				ProjectBindingDescriptor descriptor = SD.ProjectService.ProjectBindings.FirstOrDefault(b => b.Language == language);
				IProjectBinding languageinfo = (descriptor != null) ? descriptor.Binding : null;
				
				if (languageinfo == null) {
					MessageService.ShowError(
						StringParser.Parse("${res:ICSharpCode.SharpDevelop.Internal.Templates.ProjectDescriptor.CantCreateProjectWithTypeError}",
						                   new StringTagPair("type", language)));
					return false;
				}
				
				DirectoryName projectBasePath = projectCreateOptions.ProjectBasePath;
				string newProjectName = StringParser.Parse(name, new StringTagPair("ProjectName", projectCreateOptions.ProjectName));
				Directory.CreateDirectory(projectBasePath);
				FileName projectLocation = projectBasePath.CombineFile(newProjectName + descriptor.ProjectFileExtension);
				ProjectCreateInformation info = new ProjectCreateInformation(parentSolution, projectLocation);
				info.TargetFramework = projectCreateOptions.TargetFramework;
				
				StringBuilder standardNamespace = new StringBuilder();
				// filter 'illegal' chars from standard namespace
				if (!string.IsNullOrEmpty(newProjectName)) {
					char ch = '.';
					for (int i = 0; i < newProjectName.Length; ++i) {
						if (ch == '.') {
							// at beginning or after '.', only a letter or '_' is allowed
							ch = newProjectName[i];
							if (!Char.IsLetter(ch)) {
								standardNamespace.Append('_');
							} else {
								standardNamespace.Append(ch);
							}
						} else {
							ch = newProjectName[i];
							// can only contain letters, digits or '_'
							if (!Char.IsLetterOrDigit(ch) && ch != '.') {
								standardNamespace.Append('_');
							} else {
								standardNamespace.Append(ch);
							}
						}
					}
				}
				
				info.TypeGuid = descriptor.TypeGuid;
				info.RootNamespace = standardNamespace.ToString();
				info.ProjectName = newProjectName;
				if (!string.IsNullOrEmpty(defaultPlatform))
					info.ActiveProjectConfiguration = new ConfigurationAndPlatform("Debug", defaultPlatform);
				
				RunPreCreateActions(info);
				
				StringParserPropertyContainer.FileCreation["StandardNamespace"] = info.RootNamespace;
				
				if (File.Exists(projectLocation))
				{
					
					if (!MessageService.AskQuestion(
						StringParser.Parse("${res:ICSharpCode.SharpDevelop.Internal.Templates.ProjectDescriptor.OverwriteProjectQuestion}",
						                   new StringTagPair("projectLocation", projectLocation)),
						"${res:ICSharpCode.SharpDevelop.Internal.Templates.ProjectDescriptor.OverwriteQuestion.InfoName}"))
					{
						return false; //The user doesnt want to overwrite the project...
					}
				}
				
				//Show prompt if any of the files exist
				StringBuilder existingFileNames = new StringBuilder();
				foreach (FileDescriptionTemplate file in files)
				{
					string fileName = Path.Combine(projectBasePath, StringParser.Parse(file.Name, new StringTagPair("ProjectName", info.ProjectName)));
					
					if (File.Exists(fileName))
					{
						if (existingFileNames.Length > 0)
							existingFileNames.Append(", ");
						existingFileNames.Append(Path.GetFileName(fileName));
					}
				}
				
				bool overwriteFiles = true;
				if (existingFileNames.Length > 0)
				{
					if (!MessageService.AskQuestion(
						StringParser.Parse("${res:ICSharpCode.SharpDevelop.Internal.Templates.ProjectDescriptor.OverwriteQuestion}",
						                   new StringTagPair("fileNames", existingFileNames.ToString())),
						"${res:ICSharpCode.SharpDevelop.Internal.Templates.ProjectDescriptor.OverwriteQuestion.InfoName}"))
					{
						overwriteFiles = false;
					}
				}
				
				
				
				#region Copy files to target directory
				foreach (FileDescriptionTemplate file in files)
				{
					string fileName = Path.Combine(projectBasePath, StringParser.Parse(file.Name, new StringTagPair("ProjectName", info.ProjectName)));
					if (File.Exists(fileName) && !overwriteFiles)
					{
						continue;
					}
					
					try
					{
						if (!Directory.Exists(Path.GetDirectoryName(fileName))) {
							Directory.CreateDirectory(Path.GetDirectoryName(fileName));
						}
						if (!String.IsNullOrEmpty(file.BinaryFileName)) {
							// Binary content
							File.Copy(file.BinaryFileName, fileName, true);
						} else {
							// Textual content
							StreamWriter sr = new StreamWriter(File.Create(fileName), SD.FileService.DefaultFileEncoding);
							string fileContent = StringParser.Parse(file.Content,
							                                        new StringTagPair("ProjectName", projectCreateOptions.ProjectName),
							                                        new StringTagPair("SolutionName", projectCreateOptions.SolutionName),
							                                        new StringTagPair("FileName", fileName));
							fileContent = StringParser.Parse(fileContent);
							if (SD.EditorControlService.GlobalOptions.IndentationString != "\t") {
								fileContent = fileContent.Replace("\t", SD.EditorControlService.GlobalOptions.IndentationString);
							}
							sr.Write(fileContent);
							sr.Close();
						}
					}
					catch (Exception ex)
					{
						MessageService.ShowException(ex, "Exception writing " + fileName);
					}
				}
				#endregion
				
				#region Create Project
				try {
					info.InitializeTypeSystem = false;
					project = languageinfo.CreateProject(info);
				} catch (ProjectLoadException ex) {
					MessageService.ShowError(ex.Message);
					return false;
				}
				#endregion
				
				#region Create Project Items, Imports and Files
				// Add Project items
				if (!project.Items.IsReadOnly)
				{
					foreach (ProjectItem projectItem in projectItems) {
						ProjectItem newProjectItem = new UnknownProjectItem(
							project,
							StringParser.Parse(projectItem.ItemType.ItemName),
							StringParser.Parse(projectItem.Include,
							                   new StringTagPair("ProjectName", projectCreateOptions.ProjectName),
							                   new StringTagPair("SolutionName", projectCreateOptions.SolutionName))
						);
						foreach (string metadataName in projectItem.MetadataNames) {
							string metadataValue = projectItem.GetMetadata(metadataName);
							// if the input contains any special MSBuild sequences, don't escape the value
							// we want to escape only when the special characters are introduced by the StringParser.Parse replacement
							if (metadataValue.Contains("$(") || metadataValue.Contains("%"))
								newProjectItem.SetMetadata(StringParser.Parse(metadataName), StringParser.Parse(metadataValue));
							else
								newProjectItem.SetEvaluatedMetadata(StringParser.Parse(metadataName), StringParser.Parse(metadataValue));
						}
						project.Items.Add(newProjectItem);
					}
				}
				
				// Add properties from <PropertyGroup>
				// This must be done before adding <Imports>, because the import path can refer to properties.
				if (projectProperties.Count > 0) {
					if (!(project is MSBuildBasedProject))
						throw new Exception("<PropertyGroup> may be only used in project templates for MSBuildBasedProjects");
					
					foreach (ProjectProperty p in projectProperties) {
						((MSBuildBasedProject)project).SetProperty(
							StringParser.Parse(p.Configuration),
							StringParser.Parse(p.Platform),
							StringParser.Parse(p.Name),
							StringParser.Parse(p.Value),
							p.Location,
							p.ValueIsLiteral
						);
					}
				}
				
				// Add Imports
				if (clearExistingImports || projectImports.Count > 0) {
					MSBuildBasedProject msbuildProject = project as MSBuildBasedProject;
					if (msbuildProject == null)
						throw new Exception("<Imports> may be only used in project templates for MSBuildBasedProjects");
					try {
						msbuildProject.PerformUpdateOnProjectFile(
							delegate {
								var projectFile = msbuildProject.MSBuildProjectFile;
								if (clearExistingImports) {
									foreach (var import in projectFile.Imports.ToArray())
										projectFile.RemoveChild(import);
								}
								foreach (Import projectImport in projectImports) {
									projectFile.AddImport(projectImport.Key).Condition = projectImport.Value;
								}
								
							});
					} catch (InvalidProjectFileException ex) {
						string message;
						if (string.IsNullOrEmpty(importsFailureMessage)) {
							message = "Error creating project:\n" + ex.Message;
						} else {
							message = importsFailureMessage + "\n\n" + ex.Message;
						}
						throw new ProjectLoadException(message, ex);
					}
				}
				
				// Add Files
				if (!project.Items.IsReadOnly) {
					
					foreach (FileDescriptionTemplate file in files) {
						string fileName = Path.Combine(projectBasePath, StringParser.Parse(file.Name, new StringTagPair("ProjectName", projectCreateOptions.ProjectName)));
						FileProjectItem projectFile = new FileProjectItem(project, project.GetDefaultItemType(fileName));
						
						projectFile.Include = FileUtility.GetRelativePath(project.Directory, fileName);
						
						file.SetProjectItemProperties(projectFile);
						
						project.Items.Add(projectFile);
					}
				}
				
				#endregion
				
				RunCreateActions(project);
				
				project.ProjectCreationComplete();
				
				// Save project
				project.Save();
				
				// HACK : close and reload
				var fn = project.FileName;
				project.Dispose();
				ProjectLoadInformation loadInfo = new ProjectLoadInformation(parentSolution, fn, fn.GetFileNameWithoutExtension());
				project = SD.ProjectService.LoadProject(loadInfo);
				target.Items.Add(project);
				project.ProjectLoaded();
				
				SD.GetRequiredService<IProjectServiceRaiseEvents>().RaiseProjectCreated(new ProjectEventArgs(project));
				templateResults.NewProjects.Add(project);
				success = true;
				return true;
			} finally {
				if (project != null && !success)
					project.Dispose();
			}
		}
Пример #24
0
		public FSharpProject(ProjectCreateInformation info) : base(info)
		{
		}
Пример #25
0
		public ILAsmProject(ProjectCreateInformation info)
			: base(info)
		{
			this.AddImport(@"$(ILAsmAddInPath)\SharpDevelop.Build.MSIL.Targets", null);
		}