internal static void TryAddFile(IMSBuildNuGetProjectSystem msBuildNuGetProjectSystem, string path, Func <Stream> content) { if (msBuildNuGetProjectSystem.FileExistsInProject(path)) { // file exists in project, ask user if he wants to overwrite or ignore var conflictMessage = string.Format(CultureInfo.CurrentCulture, Strings.FileConflictMessage, path, msBuildNuGetProjectSystem.ProjectName); var fileConflictAction = msBuildNuGetProjectSystem.NuGetProjectContext.ResolveFileConflict(conflictMessage); if (fileConflictAction == FileConflictAction.Overwrite || fileConflictAction == FileConflictAction.OverwriteAll) { // overwrite msBuildNuGetProjectSystem.NuGetProjectContext.Log(MessageLevel.Info, Strings.Info_OverwritingExistingFile, path); using (var stream = content()) { msBuildNuGetProjectSystem.AddFile(path, stream); } } else { // ignore msBuildNuGetProjectSystem.NuGetProjectContext.Log(MessageLevel.Warning, Strings.Warning_FileAlreadyExists, path); } } else { msBuildNuGetProjectSystem.AddFile(path, content()); } }
internal static void TryAddFile(IMSBuildNuGetProjectSystem msBuildNuGetProjectSystem, string path, Func<Stream> content) { if (msBuildNuGetProjectSystem.FileExistsInProject(path)) { // file exists in project, ask user if he wants to overwrite or ignore string conflictMessage = String.Format(CultureInfo.CurrentCulture, Strings.FileConflictMessage, path, msBuildNuGetProjectSystem.ProjectName); FileConflictAction fileConflictAction = msBuildNuGetProjectSystem.NuGetProjectContext.ResolveFileConflict(conflictMessage); if (fileConflictAction == FileConflictAction.Overwrite || fileConflictAction == FileConflictAction.OverwriteAll) { // overwrite msBuildNuGetProjectSystem.NuGetProjectContext.Log(MessageLevel.Info, Strings.Info_OverwritingExistingFile, path); using (Stream stream = content()) { msBuildNuGetProjectSystem.AddFile(path, stream); } } else { // ignore msBuildNuGetProjectSystem.NuGetProjectContext.Log(MessageLevel.Warning, Strings.Warning_FileAlreadyExists, path); } } else { msBuildNuGetProjectSystem.AddFile(path, content()); } }
internal static void AddFile(IMSBuildNuGetProjectSystem msBuildNuGetProjectSystem, string path, Action <Stream> writeToStream) { using (var memoryStream = new MemoryStream()) { writeToStream(memoryStream); memoryStream.Seek(0, SeekOrigin.Begin); msBuildNuGetProjectSystem.AddFile(path, memoryStream); } }
/// <summary> /// Creates a .refresh file in bin directory of the IFileSystem that points to the assembly being installed. /// This works around issues in DTE's AddReference method when dealing with GACed binaries. /// </summary> /// <remarks>Adds the file to disk ONLY!</remarks> /// <param name="root">the root path is dte full path</param> /// <param name="assemblyPath">The relative path to the assembly being added</param> public static void CreateRefreshFile(string root, string assemblyPath, IMSBuildNuGetProjectSystem msbuildNuGetProjectSystem) { string refreshFilePath = CreateRefreshFilePath(root, assemblyPath); if (!FileSystemUtility.FileExists(root, refreshFilePath)) { try { using (var stream = CreateRefreshFileStream(root, assemblyPath)) { msbuildNuGetProjectSystem.AddFile(refreshFilePath, stream); } } catch (UnauthorizedAccessException exception) { // log IO permission error ExceptionHelper.WriteToActivityLog(exception); } } }
public static void AddFile(IMSBuildNuGetProjectSystem msBuildNuGetProjectSystem, string path, Action<Stream> writeToStream) { using (var memoryStream = new MemoryStream()) { writeToStream(memoryStream); memoryStream.Seek(0, SeekOrigin.Begin); msBuildNuGetProjectSystem.AddFile(path, memoryStream); } }