static MSBuildObject GetInsertBeforeObject (MSBuildProject project, ImportLocation importLocation) { if (importLocation == ImportLocation.Top) { return project.GetAllObjects ().FirstOrDefault (); } // Return an unknown MSBuildItem instead of null so the MSBuildProject adds the import as the last // child in the project. return new MSBuildItem (); }
void AddPackagingPropsImport (MSBuildProject msproject) { MSBuildObject insertBefore = msproject.GetAllObjects ().FirstOrDefault (); msproject.AddNewImport ( @"$(NuGetAuthoringPath)\NuGet.Packaging.Authoring.props", @"Exists('$(NuGetAuthoringPath)\NuGet.Packaging.Authoring.props')", insertBefore); }
public void StartWhitespaceForImportInsertedAsFirstChild () { string projectFile = Util.GetSampleProject ("ConsoleApp-VS2013", "ConsoleApplication.csproj"); var p = new MSBuildProject (); p.Load (projectFile); p.Evaluate (); var firstChild = p.GetAllObjects ().First (); MSBuildImport import = p.AddNewImport ("MyImport.targets", beforeObject: firstChild); Assert.AreEqual (p.TextFormat.NewLine, p.StartWhitespace); Assert.AreEqual (" ", import.StartWhitespace); }