{"id":16473167,"url":"https://github.com/binki/publishsymlinkwebconfigfileaccesserrorrepro","last_synced_at":"2025-02-28T06:28:06.090Z","repository":{"id":50273002,"uuid":"518660734","full_name":"binki/PublishSymlinkWebConfigFileAccessErrorRepro","owner":"binki","description":"Reproduce a Microsoft.NET.Sdk.Web hardlink publishing issue","archived":false,"fork":false,"pushed_at":"2022-07-28T01:39:28.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-11T02:24:37.881Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/binki.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-07-28T01:27:31.000Z","updated_at":"2022-07-28T01:28:00.000Z","dependencies_parsed_at":"2022-08-04T03:15:23.865Z","dependency_job_id":null,"html_url":"https://github.com/binki/PublishSymlinkWebConfigFileAccessErrorRepro","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binki%2FPublishSymlinkWebConfigFileAccessErrorRepro","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binki%2FPublishSymlinkWebConfigFileAccessErrorRepro/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binki%2FPublishSymlinkWebConfigFileAccessErrorRepro/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binki%2FPublishSymlinkWebConfigFileAccessErrorRepro/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/binki","download_url":"https://codeload.github.com/binki/PublishSymlinkWebConfigFileAccessErrorRepro/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241111804,"owners_count":19911563,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T12:25:35.286Z","updated_at":"2025-02-28T06:28:06.072Z","avatar_url":"https://github.com/binki.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"This project demonstrates a failure in web publish that occurs when\nusing hardlinks for publish. This is [Visual Studio Developer\nCommunity Issue\n10105786](https://developercommunity.visualstudio.com/t/-/10105786)\n\nTo reduce storage usage, there are [multiple properties which control\nusage of hard links](https://github.com/dotnet/msbuild/issues/3788)\n(for which I cannot find proper documentation!). These are:\n\n* `CreateHardLinksForCopyFilesToOutputDirectoryIfPossible`\n* `CreateHardLinksForCopyAdditionalFilesIfPossible`\n* `CreateHardLinksForCopyLocalIfPossible`\n* `CreateHardLinksForPublishFilesIfPossible`\n\nOne can set these all `true` in `Directory.Build.props`. The benefit\nis that the multiple copies of binaries in `bin/` folders in a large\nsolution in which many projects depend on each other can all refer to\nthe same file, taking up less disk space.\n\nLots of unix tools use this technique to speed up copies (by creating\nadditional links instad of actually copying) and this behavior is\nexpected. However, in the Windows world, this is still not normal. And\ntooling does not always support it well because it is still off by\ndefault, further perpetuating the idea that this is abnormal on\nWindows.\n\nThe `Microsoft.NET.Sdk.Web` MSBuild SDK falls into this latter\ncategory of tooling which does not support this well. If you have a\n`web.config` in your project and attempt to publish with\n`CreateHardLinksForPublishFilesIfPossible` set to `true`, the publish\nprocess will perform these steps during the publish:\n\n1. Create a hardlink named `«publishDir»\\web.config` referring to `«projectDir»\\web.config`.\n2. Execute `web.config` a transformations task which attempts to open `«projectDir»\\web.config` for reading and, prior to closing it, attempts to open `«publishDir»\\web.config` for writing.\n\nTo reproduce this:\n\n1. Clone this project.\n2. Build it once.\n3. Use the Publish to Local Folder publishing option.\n4. Encounter an error:\n\n   ```\n   C:\\Program Files\\dotnet\\sdk\\6.0.302\\Sdks\\Microsoft.NET.Sdk.Publish\\targets\\TransformTargets\\Microsoft.NET.Sdk.Publish.TransformFiles.targets(50,5): Error MSB4018: The \"TransformWebConfig\" task failed unexpectedly.\n   System.IO.IOException: The process cannot access the file 'C:\\Users\\ohnob\\AppData\\Local\\Temp\\PublishSymlinkWebConfigFileAccessErrorRepro\\PublishSymlinkWebConfigFileAccessErrorRepro\\obj\\Release\\net6.0\\PubTmp\\Out\\web.config' because it is being used by another process.\n      at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)\n      at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite, Boolean checkHost)\n      at Microsoft.NET.Sdk.Publish.Tasks.TransformWebConfig.Execute()\n      at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()\n      at Microsoft.Build.BackEnd.TaskBuilder.\u003cExecuteInstantiatedTask\u003ed__26.MoveNext()\n   ```\n\nFortunately, this fails and nothing is hurt. However, if the\ntransformation task closed `«projectDir»\\web.config` prior to opening\n«publishDir»\\web.config` for writing, we would have more trouble—the\ntransformations, which should not be included in source control, would\nbe written to `«publishDir»\\web.config` and, likely, accidentally get\ncommitted to source control!\n\nThe correct way to handle this situation is to, like unix tools,\nensure that hardlinks are broken. Do this by:\n\n1. Open a new, temporary file.\n2. Open and read the `«projectDir»\\web.config`.\n3. Execute the transformation.\n4. Close `«projectDir»\\web.config`.\n5. Close the new, temporary file.\n6. Rename the new, temporary file to `«publishDir»\\web.config`.\n\nThis last step breaks the link.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinki%2Fpublishsymlinkwebconfigfileaccesserrorrepro","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbinki%2Fpublishsymlinkwebconfigfileaccesserrorrepro","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinki%2Fpublishsymlinkwebconfigfileaccesserrorrepro/lists"}