public override int Run(string fileOrDirectory) { var projects = new ProjectCollection(); MsbuildProject msbuildProj = MsbuildProject.FromFileOrDirectory(projects, fileOrDirectory); if (RemainingArguments.Count == 0) { throw new GracefulException(CommonLocalizableStrings.SpecifyAtLeastOneReferenceToAdd); } string frameworkString = _frameworkOption.Value(); PathUtility.EnsureAllPathsExist(RemainingArguments, CommonLocalizableStrings.ReferenceDoesNotExist); List <MsbuildProject> refs = RemainingArguments .Select((r) => MsbuildProject.FromFile(projects, r)) .ToList(); if (frameworkString == null) { foreach (var tfm in msbuildProj.GetTargetFrameworks()) { foreach (var @ref in refs) { if ([email protected](tfm)) { Reporter.Error.Write(GetProjectNotCompatibleWithFrameworksDisplayString( @ref, msbuildProj.GetTargetFrameworks().Select((fx) => fx.GetShortFolderName()))); return(1); } } } } else { var framework = NuGetFramework.Parse(frameworkString); if (!msbuildProj.IsTargettingFramework(framework)) { Reporter.Error.WriteLine(string.Format( CommonLocalizableStrings.ProjectDoesNotTargetFramework, msbuildProj.ProjectRootElement.FullPath, frameworkString)); return(1); } foreach (var @ref in refs) { if ([email protected](framework)) { Reporter.Error.Write(GetProjectNotCompatibleWithFrameworksDisplayString( @ref, new string[] { frameworkString })); return(1); } } } var relativePathReferences = RemainingArguments.Select((r) => PathUtility.GetRelativePath(msbuildProj.ProjectDirectory, Path.GetFullPath(r))).ToList(); int numberOfAddedReferences = msbuildProj.AddProjectToProjectReferences( _frameworkOption.Value(), relativePathReferences); if (numberOfAddedReferences != 0) { msbuildProj.ProjectRootElement.Save(); } return(0); }
public override int Execute() { var projects = new ProjectCollection(); MsbuildProject msbuildProj = MsbuildProject.FromFileOrDirectory(projects, _fileOrDirectory); var frameworkString = _appliedCommand.ValueOrDefault <string>("framework"); PathUtility.EnsureAllPathsExist(_appliedCommand.Arguments, CommonLocalizableStrings.ReferenceDoesNotExist); List <MsbuildProject> refs = _appliedCommand.Arguments .Select((r) => MsbuildProject.FromFile(projects, r)) .ToList(); if (frameworkString == null) { foreach (var tfm in msbuildProj.GetTargetFrameworks()) { foreach (var @ref in refs) { if ([email protected](tfm)) { Reporter.Error.Write(GetProjectNotCompatibleWithFrameworksDisplayString( @ref, msbuildProj.GetTargetFrameworks().Select((fx) => fx.GetShortFolderName()))); return(1); } } } } else { var framework = NuGetFramework.Parse(frameworkString); if (!msbuildProj.IsTargetingFramework(framework)) { Reporter.Error.WriteLine(string.Format( CommonLocalizableStrings.ProjectDoesNotTargetFramework, msbuildProj.ProjectRootElement.FullPath, frameworkString)); return(1); } foreach (var @ref in refs) { if ([email protected](framework)) { Reporter.Error.Write(GetProjectNotCompatibleWithFrameworksDisplayString( @ref, new string[] { frameworkString })); return(1); } } } var relativePathReferences = _appliedCommand.Arguments.Select((r) => PathUtility.GetRelativePath(msbuildProj.ProjectDirectory, Path.GetFullPath(r))) .ToList(); int numberOfAddedReferences = msbuildProj.AddProjectToProjectReferences( frameworkString, relativePathReferences); if (numberOfAddedReferences != 0) { msbuildProj.ProjectRootElement.Save(); } return(0); }
public override int Execute() { var projects = new ProjectCollection(); bool interactive = _parseResult.HasOption(AddProjectToProjectReferenceParser.InteractiveOption); MsbuildProject msbuildProj = MsbuildProject.FromFileOrDirectory( projects, _fileOrDirectory, interactive); var frameworkString = _parseResult.ValueForOption <string>(AddProjectToProjectReferenceParser.FrameworkOption); var arguments = _parseResult.ValueForArgument <IReadOnlyCollection <string> >(AddProjectToProjectReferenceParser.ProjectPathArgument); PathUtility.EnsureAllPathsExist(arguments, CommonLocalizableStrings.CouldNotFindProjectOrDirectory, true); List <MsbuildProject> refs = arguments .Select((r) => MsbuildProject.FromFileOrDirectory(projects, r, interactive)) .ToList(); if (frameworkString == null) { foreach (var tfm in msbuildProj.GetTargetFrameworks()) { foreach (var @ref in refs) { if ([email protected](tfm)) { Reporter.Error.Write(GetProjectNotCompatibleWithFrameworksDisplayString( @ref, msbuildProj.GetTargetFrameworks().Select((fx) => fx.GetShortFolderName()))); return(1); } } } } else { var framework = NuGetFramework.Parse(frameworkString); if (!msbuildProj.IsTargetingFramework(framework)) { Reporter.Error.WriteLine(string.Format( CommonLocalizableStrings.ProjectDoesNotTargetFramework, msbuildProj.ProjectRootElement.FullPath, frameworkString)); return(1); } foreach (var @ref in refs) { if ([email protected](framework)) { Reporter.Error.Write(GetProjectNotCompatibleWithFrameworksDisplayString( @ref, new string[] { frameworkString })); return(1); } } } var relativePathReferences = refs.Select((r) => Path.GetRelativePath( msbuildProj.ProjectDirectory, r.ProjectRootElement.FullPath)).ToList(); int numberOfAddedReferences = msbuildProj.AddProjectToProjectReferences( frameworkString, relativePathReferences); if (numberOfAddedReferences != 0) { msbuildProj.ProjectRootElement.Save(); } return(0); }