public async Task AddFrameworkReferenceAsync(string name, string packageId) { await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); try { AddGacReference(name); NuGetProjectContext.Log(ProjectManagement.MessageLevel.Debug, Strings.Debug_AddGacReference, name, ProjectName); } catch (Exception e) { if (IsReferenceUnavailableException(e)) { var frameworkName = await VsProjectAdapter.GetDotNetFrameworkNameAsync(); if (FrameworkAssemblyResolver.IsFrameworkFacade(name, frameworkName)) { NuGetProjectContext.Log(ProjectManagement.MessageLevel.Info, Strings.FailedToAddFacadeReference, name, packageId); return; } } throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Strings.FailedToAddGacReference, packageId, name), e); } }
public override void RemoveImport(string targetFullPath) { if (string.IsNullOrEmpty(targetFullPath)) { throw new ArgumentNullException(nameof(targetFullPath), CommonResources.Argument_Cannot_Be_Null_Or_Empty); } NuGetUIThreadHelper.JoinableTaskFactory.Run(async delegate { var root = await VsProjectAdapter.GetProjectDirectoryAsync(); // For VS 2012 or above, the operation has to be done inside the Writer lock var relativeTargetPath = PathUtility.GetRelativePath(PathUtility.EnsureTrailingSlash(root), targetFullPath); await RemoveImportStatementAsync(relativeTargetPath); }); }
public override void AddImport(string targetFullPath, ImportLocation location) { // For VS 2012 or above, the operation has to be done inside the Writer lock if (string.IsNullOrEmpty(targetFullPath)) { throw new ArgumentNullException(nameof(targetFullPath)); } NuGetUIThreadHelper.JoinableTaskFactory.Run(async delegate { var root = await VsProjectAdapter.GetProjectDirectoryAsync(); var relativeTargetPath = PathUtility.GetRelativePath(PathUtility.EnsureTrailingSlash(root), targetFullPath); await AddImportStatementAsync(location, relativeTargetPath); }); }
public async Task InitializeProperties() { _targetFramework = await VsProjectAdapter.GetTargetFrameworkAsync(); }