public override void AddReference(string referencePath) { string name = Path.GetFileNameWithoutExtension(referencePath); try { var root = EnvDTEProjectUtility.GetFullPath(EnvDTEProject); EnvDTEProjectUtility.GetAssemblyReferences(EnvDTEProject).AddFromFile(PathUtility.GetAbsolutePath(root, referencePath)); // Always create a refresh file. Vs does this for us in most cases, however for GACed binaries, it resorts to adding a web.config entry instead. // This may result in deployment issues. To work around ths, we'll always attempt to add a file to the bin. RefreshFileUtility.CreateRefreshFile(root, PathUtility.GetAbsolutePath(EnvDTEProjectUtility.GetFullPath(EnvDTEProject), referencePath), this); NuGetProjectContext.Log(MessageLevel.Debug, Strings.Debug_AddReference, name, ProjectName); } catch (Exception e) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Strings.FailedToAddReference, name), e); } }
public override async Task AddReferenceAsync(string referencePath) { await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); var name = Path.GetFileNameWithoutExtension(referencePath); try { EnvDTEProjectUtility.GetAssemblyReferences(VsProjectAdapter.Project).AddFromFile(PathUtility.GetAbsolutePath(ProjectFullPath, referencePath)); // Always create a refresh file. Vs does this for us in most cases, however for GACed binaries, it resorts to adding a web.config entry instead. // This may result in deployment issues. To work around ths, we'll always attempt to add a file to the bin. RefreshFileUtility.CreateRefreshFile(ProjectFullPath, PathUtility.GetAbsolutePath(ProjectFullPath, referencePath), this); NuGetProjectContext.Log(ProjectManagement.MessageLevel.Debug, $"Added reference '{name}' to project:'{ProjectName}' "); } catch (Exception e) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Strings.FailedToAddReference, name), e); } }