Skip to content

Weird binary file lock with PublishSingleFile=true #1260

@JustArchi

Description

@JustArchi

Background

Hello.

I have a quite unusual scenario where my application would like to move its own binary while running. On linux, I'm free to do anything I want with currently running binary, including moving it. On Windows, at least usually, I'm not able to delete the running binary, but I'm still able to move it, which satisfies my usage.

Issue

I've noticed inconsistency in regards to this when using PublishSingleFile=true. Ideally I'd like to keep being able to move the binary away, which I use right now with no further issues.

In particular, this is what happens (only on Windows):

  • When you launch a PublishSingleFile=true project for the first time, or after you've manually cleaned %TEMP%\.net, the app unpacks itself and you're free to rename/move the binary as you please.
  • However, when you launch that project again, with the content already extracted, you're no longer able to do anything with the original binary, including moving/renaming it. The binary now holds exclusive file lock to itself.

If anything, I'd expect this behaviour to be consistent, or logically, more restrictive when we unpack for the first time, rather than when re-using existing structure. Instead, it's entirely different, to the point that makes me believe it's something worth reporting or getting more details about.

Of course, judging by the above, the "workaround" for my use case is manually cleaning %TEMP%\.net after each program run, which is a very weird solution, but a working one. I'm not entirely sure why the application would hold exclusive file access when re-using the existing structure but not when unpacking for the first time, which is exactly why I've decided to create this issue.

Ideally it'd be nice if that lock wasn't needed (so I could keep using my planned use case), but in case you actually have reasoning for it, you'd likely want to keep it up for both cases and not only one that is effectively a subset of operations (run) in another one (unpack and run). In any case, at least in my opinion, it's something worth investigating and deciding whether that exclusive file lock could be released (like when run for the first time), or if it's actually needed in both cases (in which case you might want to add it to first run as well).

Thank you in advance for your time in regards to this isssue.

.NET Core SDK (reflecting any global.json):
 Version:   3.1.100
 Commit:    cd82f021f4

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.18362
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\3.1.100\

Host (useful for support):
  Version: 3.1.0
  Commit:  65f04fb6db

Metadata

Metadata

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions