public void FindItems() { ProjectRootElement projectRootElement = ProjectRootElement.Create(); ProjectItemGroupElement itemGroup = projectRootElement.AddItemGroup(); itemGroup.AddItem(AnalyzerItemsPredictor.AnalyzerItemName, "Foo.dll"); itemGroup.AddItem(AnalyzerItemsPredictor.AnalyzerItemName, "Bar.dll"); itemGroup.AddItem(AnalyzerItemsPredictor.AnalyzerItemName, "Baz.dll"); ProjectInstance projectInstance = TestHelpers.CreateProjectInstanceFromRootElement(projectRootElement); var expectedInputFiles = new[] { new PredictedItem("Foo.dll", nameof(AnalyzerItemsPredictor)), new PredictedItem("Bar.dll", nameof(AnalyzerItemsPredictor)), new PredictedItem("Baz.dll", nameof(AnalyzerItemsPredictor)), }; new AnalyzerItemsPredictor() .GetProjectPredictions(projectInstance) .AssertPredictions( projectInstance, expectedInputFiles, null, null, null); }
private static ProjectInstance CreateTestProjectInstance(string fileName, bool hasProjectReferences = true, bool isEnabled = true) { ProjectRootElement projectRootElement = ProjectRootElement.Create($@"ServiceFabricApp\{fileName}"); // These are generally set in Microsoft.VisualStudio.Azure.Fabric.Application.targets ProjectPropertyGroupElement propertyGroup = projectRootElement.AddPropertyGroup(); propertyGroup.AddProperty(ServiceFabricServiceManifestPredictor.ApplicationPackageRootFolderPropertyName, "ApplicationPackageRoot"); propertyGroup.AddProperty(ServiceFabricServiceManifestPredictor.ServicePackageRootFolderPropertyName, "PackageRoot"); if (isEnabled) { propertyGroup.AddProperty(ServiceFabricServiceManifestPredictor.UpdateServiceFabricApplicationManifestEnabledPropertyName, "true"); } if (hasProjectReferences) { ProjectItemGroupElement itemGroup = projectRootElement.AddItemGroup(); itemGroup.AddItem(ServiceFabricServiceManifestPredictor.ProjectReferenceItemName, @"..\Service1\Service1.csproj"); itemGroup.AddItem(ServiceFabricServiceManifestPredictor.ProjectReferenceItemName, @"..\Service2\Service2.csproj"); } // Extra service manifests, and some extraneous files too Directory.CreateDirectory(@"ServiceFabricApp\ApplicationPackageRoot"); File.WriteAllText($@"ServiceFabricApp\ApplicationPackageRoot\{ServiceFabricServiceManifestPredictor.ServiceManifestFileName}", "SomeContent"); // Not in a subdir, should not get picked up File.WriteAllText($@"ServiceFabricApp\ApplicationPackageRoot\extraneous.txt", "SomeContent"); Directory.CreateDirectory(@"ServiceFabricApp\ApplicationPackageRoot\Foo"); File.WriteAllText($@"ServiceFabricApp\ApplicationPackageRoot\Foo\{ServiceFabricServiceManifestPredictor.ServiceManifestFileName}", "SomeContent"); File.WriteAllText($@"ServiceFabricApp\ApplicationPackageRoot\Foo\extraneous.txt", "SomeContent"); Directory.CreateDirectory(@"ServiceFabricApp\ApplicationPackageRoot\Bar"); File.WriteAllText($@"ServiceFabricApp\ApplicationPackageRoot\Bar\{ServiceFabricServiceManifestPredictor.ServiceManifestFileName}", "SomeContent"); File.WriteAllText($@"ServiceFabricApp\ApplicationPackageRoot\Bar\extraneous.txt", "SomeContent"); return(TestHelpers.CreateProjectInstanceFromRootElement(projectRootElement)); }
void GenerateCompileIncludes(ProjectItemGroupElement itemGroup) { foreach (var include in new[] { "Test.cs", "Test2.cs", "Test3.cs" }) { itemGroup.AddItem ("Compile", ProjectCollection.Escape (include), new[] { new KeyValuePair<string, string> ("SubType", "Code") }); } foreach (var resource in new[] { "Test.resx", "Test2.resx", "Test3.resx" }) { itemGroup.AddItem ("EmbeddedResource", ProjectCollection.Escape (resource), new[] { new KeyValuePair<string, string> ("LogicalName", "Name.Space.Test") }); } }
private static ProjectInstance CreateTestProjectInstance(string fileName) { ProjectRootElement projectRootElement = ProjectRootElement.Create(fileName); ProjectItemGroupElement itemGroup = projectRootElement.AddItemGroup(); itemGroup.AddItem(AzureCloudServicePredictor.ServiceDefinitionItemName, "ServiceDefinition.csdef"); itemGroup.AddItem(AzureCloudServicePredictor.ServiceConfigurationItemName, "ServiceConfiguration.Local.cscfg"); itemGroup.AddItem(AzureCloudServicePredictor.ServiceConfigurationItemName, "ServiceConfiguration.Prod.cscfg"); return(TestHelpers.CreateProjectInstanceFromRootElement(projectRootElement)); }
void GenerateReferences(ProjectItemGroupElement itemGroup) { foreach (var reference in new[] { "Test.dll", "Test2.dll", "Test3.dll" }) { var name = Path.GetFileNameWithoutExtension (reference); itemGroup.AddItem ("Reference", name, new[] { new KeyValuePair<string, string> ("Name", name), new KeyValuePair<string, string> ("HintPath", ProjectCollection.Escape (reference)) }); } foreach (var reference in new[] { "mscorlib", "System", "System.Xml" }) { itemGroup.AddItem ("Reference", reference); } }
public void PreProcess(MSBuild.Project project) { if (project.ProjectFileLocation.File.EndsWith(".user", System.StringComparison.OrdinalIgnoreCase)) { return; } project.SetProperty("ProjectTypeGuids", "{00251F00-BA30-4CE4-96A2-B8A1085F37AA};{3AF33F2E-1136-4D97-BBB7-1795711AC8B8};{9092AA53-FB77-4645-B42D-1CCCA6BD08BD}"); project.SetProperty("VisualStudioVersion", "14.0"); project.Xml.AddProperty("VisualStudioVersion", "14.0").Condition = "'$(VisualStudioVersion)' == ''"; project.Xml.AddProperty("VSToolsPath", "$(MSBuildExtensionsPath32)\\Microsoft\\VisualStudio\\v$(VisualStudioVersion)").Condition = "'$(VSToolsPath)' == ''"; project.Xml.AddImport("$(VSToolsPath)\\Node.js Tools\\Microsoft.NodejsUwp.targets"); project.SetProperty("ProjectHome", "."); project.SetProperty("ProjectView", "ShowAllFiles"); project.SetProperty("OutputPath", "."); project.SetProperty("AppContainerApplication", "true"); project.SetProperty("ApplicationType", "Windows Store"); project.SetProperty("OutpApplicationTypeRevisionutPath", "8.2"); project.SetProperty("AppxPackage", "true"); project.SetProperty("WindowsAppContainer", "true"); project.SetProperty("RemoteDebugEnabled", "true"); project.SetProperty("PlatformAware", "true"); project.SetProperty("AvailablePlatforms", "x86,x64,ARM"); // Add package.json string jsonStr = "{\"name\": \"HelloWorld\",\"version\": \"0.0.0\",\"main\": \"server.js\"}"; string jsonPath = string.Format("{0}\\package.json", project.DirectoryPath); using (FileStream fs = File.Create(jsonPath)) { fs.Write(Encoding.ASCII.GetBytes(jsonStr), 0, jsonStr.Length); } ProjectItemGroupElement itemGroup = project.Xml.AddItemGroup(); itemGroup.AddItem("Content", jsonPath); }
private void AddPackageReferenceIntoItemGroup(ProjectItemGroupElement itemGroup, LibraryDependency libraryDependency) { var packageVersion = libraryDependency.LibraryRange.VersionRange.OriginalString ?? libraryDependency.LibraryRange.VersionRange.MinVersion.ToString(); var item = itemGroup.AddItem(PACKAGE_REFERENCE_TYPE_TAG, libraryDependency.Name); item.AddMetadata(VERSION_TAG, packageVersion, expressAsAttribute: true); if (libraryDependency.IncludeType != LibraryIncludeFlags.All) { var includeFlags = MSBuildStringUtility.Convert(LibraryIncludeFlagUtils.GetFlagString(libraryDependency.IncludeType)); item.AddMetadata(IncludeAssets, includeFlags, expressAsAttribute: false); } if (libraryDependency.SuppressParent != LibraryIncludeFlagUtils.DefaultSuppressParent) { var suppressParent = MSBuildStringUtility.Convert(LibraryIncludeFlagUtils.GetFlagString(libraryDependency.SuppressParent)); item.AddMetadata(PrivateAssets, suppressParent, expressAsAttribute: false); } Logger.LogInformation(string.Format(CultureInfo.CurrentCulture, Strings.Info_AddPkgAdded, libraryDependency.Name, packageVersion, itemGroup.ContainingProject.FullPath)); }
public void ProjectFinishedGenerating(Project project) { string PERSISTANCE_FOLDER = "Persistance"; ProjectItem modelsFolder = Utils.GetProjectItemFolder(project, PERSISTANCE_FOLDER) .FirstOrDefault(); List <string> projectNames = Utils.GetProjectNameFromDTE(project); if (projectNames.Count() > 0) { frmAddProjectsRef addPrjRef = new frmAddProjectsRef(projectNames); System.Windows.Forms.DialogResult settingResult = addPrjRef.ShowDialog(); IEnumerable <string> selectedProjectNames = frmAddProjectsRef.GetSelectCheckListBox.SelectedItems.OfType <string>().ToArray(); ProjectRootElement projectRoot = ProjectRootElement.Open(project.FullName); foreach (var selectedPrjName in selectedProjectNames) { if (selectedPrjName != project.Name) { ProjectItemGroupElement projectGroup01 = projectRoot.AddItemGroup(); projectGroup01.AddItem("ProjectReference", $"..\\{selectedPrjName}\\{selectedPrjName}.csproj"); } } projectRoot.Save(); } // 2020/10/12 後修正為最後才產生 ApplicationDbContext 物件 Utils.CreateDbContextFromSourceTables(project, modelsFolder, projectNames); }
private bool TryWriteProjectsFile(ProjectCollection projectCollection, FileInfo projectsFile) { Log.LogMessageFromText($"Generating file '{projectsFile.FullName}'", MessageImportance.Low); Directory.CreateDirectory(projectsFile.DirectoryName); ProjectRootElement rootElement = ProjectRootElement.Create(projectsFile.FullName); ProjectItemGroupElement projectFileItemGroup = rootElement.AddItemGroup(); ProjectItemGroupElement traversalFileItemGroup = rootElement.AddItemGroup(); foreach (Project project in projectCollection.LoadedProjects) { if (String.Equals(project.GetPropertyValue("IsTraversal"), "true", StringComparison.OrdinalIgnoreCase)) { traversalFileItemGroup.AddItem("TraversalFile", project.FullPath); } else { projectFileItemGroup.AddItem("ProjectFile", project.FullPath); } } rootElement.Save(); return(true); }
private static void InitializeVSIXProjectItems(ProjectRootElement root) { ProjectElement lastChild = root.LastChild; ProjectItemGroupElement group = root.CreateItemGroupElement(); root.InsertBeforeChild(group, lastChild); group.AddItem("None", "source.extension.vsixmanifest"); }
private static ProjectInstance CreateTestProjectInstance(string fileName) { ProjectRootElement projectRootElement = ProjectRootElement.Create($@"AzureCloudService\{fileName}"); ProjectItemGroupElement itemGroup = projectRootElement.AddItemGroup(); itemGroup.AddItem(AzureCloudServiceWorkerFilesPredictor.ProjectReferenceItemName, @"..\Worker1\Worker1.csproj"); itemGroup.AddItem(AzureCloudServiceWorkerFilesPredictor.ProjectReferenceItemName, @"..\Worker2\Worker2.csproj"); itemGroup.AddItem(AzureCloudServiceWorkerFilesPredictor.ProjectReferenceItemName, @"..\WorkerNoAppConfig\WorkerNoAppConfig.csproj"); // Add app.config files since existence is checked, but not for WorkerNoAppConfig Directory.CreateDirectory(@"Worker1"); File.WriteAllText($@"Worker1\{AzureCloudServiceWorkerFilesPredictor.AppConfigFileName}", "SomeContent"); Directory.CreateDirectory(@"Worker2"); File.WriteAllText($@"Worker2\{AzureCloudServiceWorkerFilesPredictor.AppConfigFileName}", "SomeContent"); return(TestHelpers.CreateProjectInstanceFromRootElement(projectRootElement)); }
private static void AddItems(ProjectRootElement elem, string groupName, params string[] items) { ProjectItemGroupElement group = elem.AddItemGroup(); foreach (string item in items) { group.AddItem(groupName, item); } }
private void AddDirectories(IReadOnlyCollection <string> directoriesToAdd) { foreach (string path in directoriesToAdd) { RemoveItem(_directoriesItemGroup, _directoryItems, path); ProjectItemElement item = _directoriesItemGroup.AddItem("Folder", path, Enumerable.Empty <KeyValuePair <string, string> >()); _directoryItems.Add(path, item); } }
private void UpdateCSProjectFolders(ProjectRootElement projectRoot) { var deletePhysicalName = projectRoot.FullPath; //deleteItem.Properties.Item("FullPath"); string fullPath = deletePhysicalName; string projectPath = Path.GetDirectoryName(fullPath); ProjectItemGroupElement group01 = null; if (Directory.Exists(Path.Combine(projectPath, "Models"))) { group01 = group01 ?? projectRoot.AddItemGroup(); group01.AddItem("Folder", @"Models\"); } if (Directory.Exists(Path.Combine(projectPath, "Views"))) { group01 = group01 ?? projectRoot.AddItemGroup(); group01.AddItem("Folder", @"Views\"); } }
public override bool Execute() { bool result = true; string file = Path.Combine(m_stubsPath, m_name + ".featureproj"); try { _EVAL.Project proj = new _EVAL.Project(); Microsoft.Build.Evaluation.ProjectCollection projCol = proj.ProjectCollection; ProjectPropertyGroupElement bpg = proj.Xml.AddPropertyGroup(); bpg.AddProperty("FeatureName", m_name); bpg.AddProperty("Guid", System.Guid.NewGuid().ToString("B")); bpg.AddProperty("Description", "<Add Feature Description Here>"); bpg.AddProperty("Groups", ""); bpg.AddProperty(m_name.ToUpper().Replace(".", "_") + "_FEATUREPROJ", "True"); ProjectItemGroupElement big = proj.Xml.AddItemGroup(); big.AddItem("InteropFeature", Path.GetFileNameWithoutExtension(m_assemblyName).Replace('.', '_')); big.AddItem("DriverLibs", Path.GetFileNameWithoutExtension(m_assemblyName).Replace('.', '_') + ".$(LIB_EXT)"); big.AddItem("MMP_DAT_CreateDatabase", "$(BUILD_TREE_CLIENT)\\pe\\$(ENDIANNESS)\\" + m_assemblyName); big.AddItem("RequiredProjects", Path.Combine(m_stubsPath, m_nativeProjectFile)); proj.Save(file); // after save, unload the project, so that if rebuilds it is able to regenerate the project file. ProjectRootElement pre = proj.Xml; projCol.UnloadProject(proj); projCol.UnloadProject(pre); } catch (Exception e) { Log.LogError("Error trying to create feature project file \"" + file + "\": " + e.Message); result = false; } return(result); }
private static Project CreateTestProject(params string[] compileItemIncludes) { ProjectRootElement projectRootElement = ProjectRootElement.Create(); ProjectItemGroupElement itemGroup = projectRootElement.AddItemGroup(); foreach (string compileItemInclude in compileItemIncludes) { itemGroup.AddItem("Compile", compileItemInclude); } return(TestHelpers.CreateProjectFromRootElement(projectRootElement)); }
public void Generate(string outputPath, string propertyVersionNamePrefix, string propertyPathNamePrefix, PackageRestoreData restoreData) { // Delete an existing file in case there are no properties generated and we don't end up saving the file // if (File.Exists(outputPath)) { Retry(() => File.Delete(outputPath), TimeSpan.FromMilliseconds(500)); } ProjectRootElement project = ProjectRootElement.Create(); ProjectPropertyGroupElement propertyGroup = project.AddPropertyGroup(); propertyGroup.SetProperty("MSBuildAllProjects", "$(MSBuildAllProjects);$(MSBuildThisFileFullPath)"); ProjectItemGroupElement itemGroup = project.AddItemGroup(); bool anyPropertiesCreated = false; foreach (string packageConfigPath in _packageConfigPaths) { _logger.LogMessage(MessageImportance.Low, $"Parsing '{packageConfigPath}'"); IEnumerable <PackageIdentityWithPath> parsedPackages = null; INuGetPackageConfigParser configParser = null; // A bug in nuget sometimes causes "NuGet.Configuration.NuGetConfigurationException: Unexpected failure reading NuGet.Config." when multiple instances are running in parrallel such as in the quickbuild scenario. Retry(() => configParser = _configParsersLazy.Value.FirstOrDefault(i => i.TryGetPackages(packageConfigPath, restoreData, out parsedPackages)), TimeSpan.FromMilliseconds(1000)); if (configParser != null && parsedPackages != null) { anyPropertiesCreated = true; foreach (PackageIdentityWithPath packageInfo in parsedPackages) { propertyGroup.SetProperty($"{propertyPathNamePrefix}{packageInfo.Id.Replace(".", "_")}", $"{packageInfo.FullPath}"); propertyGroup.SetProperty($"{propertyVersionNamePrefix}{packageInfo.Id.Replace(".", "_")}", $"{packageInfo.Version.ToString()}"); // Consider adding item metadata of packageid and version for ease of consumption of this property. itemGroup.AddItem("CBTNuGetPackageDir", packageInfo.FullPath); } } } // Don't save the file if no properties were created. In Visual Studio design time builds, this can be called multiple times until there are finally // properties that can be created. If we generate an empty file, it won't get regenerated once there are properties to create. // if (anyPropertiesCreated) { Retry(() => project.Save(outputPath), TimeSpan.FromMilliseconds(500)); } }
/// <summary> /// Adds the item group containting the ProjectConfiguration items to a new project. /// </summary> void AddProjectConfigurationsItemGroup() { ProjectRootElement file = MSBuildProjectFile; ProjectItemGroupElement configItemGroup = file.AddItemGroup(); configItemGroup.Label = "ProjectConfigurations"; foreach (string target in new string[] { "Debug|Win32", "Release|Win32" }) { ProjectItemElement prjConfiguration = configItemGroup.AddItem("ProjectConfiguration", target); prjConfiguration.AddMetadata("Configuration", GetConfigurationNameFromKey(target)); prjConfiguration.AddMetadata("Platform", GetPlatformNameFromKey(target)); } }
private void AddFiles(IReadOnlyCollection <string> filesToAdd) { // await InMemoryProjectSourceItemProviderExtension.CallListeners(this.SourceItemsAddingListeners, contexts, false); foreach (string path in filesToAdd) { RemoveItem(_filesItemGroup, _fileItems, path); ProjectItemElement item = _filesItemGroup.AddItem("Content", path, Enumerable.Empty <KeyValuePair <string, string> >()); _fileItems.Add(path, item); } // await InMemoryProjectSourceItemProviderExtension.CallListeners(this.SourceItemsAddedListeners, contexts, false); }
/// <summary> /// Adds the item group containting the ProjectConfiguration items to a new project. /// </summary> void AddProjectConfigurationsItemGroup() { ProjectRootElement file = MSBuildProjectFile; ProjectItemGroupElement configItemGroup = file.AddItemGroup(); configItemGroup.Label = "ProjectConfigurations"; foreach (var target in new [] { new ConfigurationAndPlatform("Debug", "Win32"), new ConfigurationAndPlatform("Release", "Win32") }) { ProjectItemElement prjConfiguration = configItemGroup.AddItem("ProjectConfiguration", target.ToString()); prjConfiguration.AddMetadata("Configuration", target.Configuration); prjConfiguration.AddMetadata("Platform", target.Platform); } }
static void AddItems(ProjectRootElement elem, string groupName, params string[] items) { ProjectItemGroupElement group = elem.AddItemGroup(); foreach (var item in items) { ProjectItemElement projItem = group.AddItem(groupName, item); //if (groupName == "Compile") //{ // projItem.AddMetadata("Link", item); //} } }
public void SkipOtherProjectTypes() { ProjectRootElement projectRootElement = ProjectRootElement.Create("project.csproj"); ProjectItemGroupElement itemGroup = projectRootElement.AddItemGroup(); itemGroup.AddItem(SqlBuildPredictor.BuildItemName, "Build1.sql"); itemGroup.AddItem(SqlBuildPredictor.BuildItemName, "Build2.sql"); itemGroup.AddItem(SqlBuildPredictor.BuildItemName, "Build3.sql"); itemGroup.AddItem(SqlBuildPredictor.PreDeployItemName, "PreDeploy1.sql"); itemGroup.AddItem(SqlBuildPredictor.PreDeployItemName, "PreDeploy2.sql"); itemGroup.AddItem(SqlBuildPredictor.PreDeployItemName, "PreDeploy3.sql"); itemGroup.AddItem(SqlBuildPredictor.PostDeployItemName, "PostDeploy1.sql"); itemGroup.AddItem(SqlBuildPredictor.PostDeployItemName, "PostDeploy2.sql"); itemGroup.AddItem(SqlBuildPredictor.PostDeployItemName, "PostDeploy3.sql"); ProjectInstance projectInstance = TestHelpers.CreateProjectInstanceFromRootElement(projectRootElement); new SqlBuildPredictor() .GetProjectPredictions(projectInstance) .AssertNoPredictions(); }
public static void AddItemsToGroup(this ProjectItemGroupElement group, IEnumerable <XElement> items, string itemType, string outputFolder) { foreach (var each in items) { var itemPath = each.AttributeValue("Include"); var newItemPath = outputFolder.RelativePathTo(itemPath.GetFullPath()); var item = group.AddItem(itemType, newItemPath); var condition = each.AttributeValue("Condition"); if (condition.Is()) { condition = condition.Replace(itemPath, newItemPath, StringComparison.InvariantCultureIgnoreCase); item.Condition = condition; } } }
private void AddPackageReferenceIntoItemGroup(ProjectItemGroupElement itemGroup, PackageDependency packageDependency) { var packageVersion = packageDependency.VersionRange.OriginalString ?? packageDependency.VersionRange.MinVersion.ToString(); var item = itemGroup.AddItem(PACKAGE_REFERENCE_TYPE_TAG, packageDependency.Id); item.AddMetadata(VERSION_TAG, packageVersion, expressAsAttribute: true); Logger.LogInformation(string.Format(CultureInfo.CurrentCulture, Strings.Info_AddPkgAdded, packageDependency.Id, packageVersion, itemGroup.ContainingProject.FullPath)); }
public void FindItems() { ProjectRootElement projectRootElement = ProjectRootElement.Create(); ProjectItemGroupElement itemGroup = projectRootElement.AddItemGroup(); itemGroup.AddItem(ApplicationDefinitionItemsPredictor.ApplicationDefinitionItemName, "App.xaml"); ProjectInstance projectInstance = TestHelpers.CreateProjectInstanceFromRootElement(projectRootElement); new ApplicationDefinitionItemsPredictor() .GetProjectPredictions(projectInstance) .AssertPredictions( projectInstance, new[] { new PredictedItem("App.xaml", nameof(ApplicationDefinitionItemsPredictor)) }, null, null, null); }
public void FindItems() { ProjectRootElement projectRootElement = ProjectRootElement.Create(); ProjectItemGroupElement itemGroup = projectRootElement.AddItemGroup(); itemGroup.AddItem(SplashScreenItemsPredictor.SplashScreenItemName, "Foo.png"); ProjectInstance projectInstance = TestHelpers.CreateProjectInstanceFromRootElement(projectRootElement); new SplashScreenItemsPredictor() .GetProjectPredictions(projectInstance) .AssertPredictions( projectInstance, new[] { new PredictedItem("Foo.png", nameof(SplashScreenItemsPredictor)) }, null, null, null); }
public void VSCTCompileItemsFindItems() { ProjectRootElement projectRootElement = ProjectRootElement.Create(); ProjectItemGroupElement itemGroup = projectRootElement.AddItemGroup(); itemGroup.AddItem(VSCTCompileItemsPredictor.VSCTCompileItemName, "SomeExtensionPackage.vsct"); ProjectInstance projectInstance = TestHelpers.CreateProjectInstanceFromRootElement(projectRootElement); new VSCTCompileItemsPredictor() .GetProjectPredictions(projectInstance) .AssertPredictions( projectInstance, new[] { new PredictedItem("SomeExtensionPackage.vsct", nameof(VSCTCompileItemsPredictor)) }, null, null, null); }
public void FindItems() { ProjectRootElement projectRootElement = ProjectRootElement.Create("project.sqlproj"); ProjectItemGroupElement itemGroup = projectRootElement.AddItemGroup(); itemGroup.AddItem(SqlBuildPredictor.BuildItemName, "Build1.sql"); itemGroup.AddItem(SqlBuildPredictor.BuildItemName, "Build2.sql"); itemGroup.AddItem(SqlBuildPredictor.BuildItemName, "Build3.sql"); itemGroup.AddItem(SqlBuildPredictor.PreDeployItemName, "PreDeploy1.sql"); itemGroup.AddItem(SqlBuildPredictor.PreDeployItemName, "PreDeploy2.sql"); itemGroup.AddItem(SqlBuildPredictor.PreDeployItemName, "PreDeploy3.sql"); itemGroup.AddItem(SqlBuildPredictor.PostDeployItemName, "PostDeploy1.sql"); itemGroup.AddItem(SqlBuildPredictor.PostDeployItemName, "PostDeploy2.sql"); itemGroup.AddItem(SqlBuildPredictor.PostDeployItemName, "PostDeploy3.sql"); ProjectInstance projectInstance = TestHelpers.CreateProjectInstanceFromRootElement(projectRootElement); var expectedInputFiles = new[] { new PredictedItem("Build1.sql", nameof(SqlBuildPredictor)), new PredictedItem("Build2.sql", nameof(SqlBuildPredictor)), new PredictedItem("Build3.sql", nameof(SqlBuildPredictor)), new PredictedItem("PreDeploy1.sql", nameof(SqlBuildPredictor)), new PredictedItem("PreDeploy2.sql", nameof(SqlBuildPredictor)), new PredictedItem("PreDeploy3.sql", nameof(SqlBuildPredictor)), new PredictedItem("PostDeploy1.sql", nameof(SqlBuildPredictor)), new PredictedItem("PostDeploy2.sql", nameof(SqlBuildPredictor)), new PredictedItem("PostDeploy3.sql", nameof(SqlBuildPredictor)), }; new SqlBuildPredictor() .GetProjectPredictions(projectInstance) .AssertPredictions( projectInstance, expectedInputFiles, null, null, null); }
private static void AddPackageReference(ProjectItemGroupElement itemGroup, PackageReference packageReference, AddVersionMetadata addVersionMetadata) { var item = itemGroup.AddItem(PackageReferenceTypeTag, packageReference.Name); addVersionMetadata(item, packageReference); AddAssetsListMetadataToPackageReference( item, PrivateAssetsMetadataAttribute, packageReference.PrivateAssets); AddAssetsListMetadataToPackageReference( item, IncludeAssetsMetadataAttribute, packageReference.IncludeAssets); AddAssetsListMetadataToPackageReference( item, ExcludeAssetsMetadataAttribute, packageReference.ExcludeAssets); }
public static void AddPackageReference(this ProjectRootElement project, string packageId, string version) { ProjectItemElement existingPackageReference = project.Items .FirstOrDefault(item => item.ItemType == PackageReferenceElementName && item.Include == packageId); if (existingPackageReference != null) { // If the package is already present, move on... if (existingPackageReference.Metadata.Any(m => m.Name == PackageReferenceVersionElementName && m.Value == version)) { return; } existingPackageReference.Parent.RemoveChild(existingPackageReference); } ProjectItemGroupElement group = GetUniformItemGroupOrNew(project, PackageReferenceElementName); group.AddItem(PackageReferenceElementName, packageId) .AddMetadata(PackageReferenceVersionElementName, version, true); }