protected FileDeploymentData PrepareNewAssetFile(FileDeploymentData parent) { return(new FileDeploymentData { FilterPath = _filterPath, InputFilePath = _inputFile.FullName, InputFileHash = null, // TODO: use Property InputFileHash if hash is needed, Parent = parent }); }
/// <summary> /// Deploys the file by copying it from source to target, OR /// deploys the file by creating a symlink at target, which points to source /// </summary> protected void DeployFile(FileDeploymentData deploymentData) { void doCopy() { // The target could also be a directory because of conflict management! if (Directory.Exists(deploymentData.OutputFilePath)) { Directory.Delete(deploymentData.OutputFilePath, true); } if (File.Exists(deploymentData.OutputFilePath)) { File.Delete(deploymentData.OutputFilePath); } File.Copy(deploymentData.InputFilePath, deploymentData.OutputFilePath, true); deploymentData.DeploymentType = DeploymentType.Copy; } if (Properties.Settings.Default.AlwaysCopyNeverSymlink || _config.Configuration == BuildConfiguration.Publish) { doCopy(); } else { var outputFile = new FileInfo(deploymentData.OutputFilePath); // TODO: Is there a more efficient way which does not require to always delete it? if (outputFile.Exists) { File.Delete(outputFile.FullName); } CreateSymbolicLink(@"\\?\" + deploymentData.OutputFilePath, @"\\?\" + deploymentData.InputFilePath, SYMBOLIC_LINK_FLAG_FILE | SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE); // Sadly, it is not guaranteed that this will work if (File.Exists(outputFile.FullName)) // Attention: do not use outputfile.Exists since that is cached! { // symlink worked deploymentData.DeploymentType = DeploymentType.Symlink; } else { doCopy(); } } }