Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publish is frequently getting Access denied to different files #2524

Closed
genifycom opened this issue Mar 30, 2019 · 12 comments
Closed

Publish is frequently getting Access denied to different files #2524

genifycom opened this issue Mar 30, 2019 · 12 comments
Labels
needs-more-info Not enough information has been provided. Please share more detail as requested.

Comments

@genifycom
Copy link

genifycom commented Mar 30, 2019

Issue Title

dotnet publish is getting access to the path denied on different files each time it is run

General

During a
dotnet publish -c Release -r win-x64
the publish is failing due to access to the path denied. The specific file changes each time dotnet publish is run. This project has a main asp.net application that references 7 class libraries in separate projects. All projects are set to use netcoreapp2.1 in their csprojs.

C:\Program Files\dotnet\sdk\2.2.105\Microsoft.Common.CurrentVersion.targets(4194,5): error MSB3021: Unable to copy file "obj\Release\netcoreapp2.1\BVData.dll" to "bin\Release\netcoreapp2.1\BVData.dll". Access to the path '...\BVData\bin\Release\netcoreapp2.1\BVData.dll' is denied. [...\BVData.csproj]

Provide details on the problem you are experiencing including the .NET Core version, operating system version and anything else that is relevant.
dotnet --version 2.2.105
The published app is set for netcoreapp2.1 in the main csproj and all referenced class libraries.

Tried this into a new empty directory with diagnostics turned on. This only shows
"...\BVTagging.sln" (Publish target) (1:2) ->
"...\BVAdmin.csproj" (Publish target) (15:6) ->
"...\BVData.csproj" (default target) (4:13) ->
(CopyFilesToOutputDirectory target) ->
C:\Program Files\dotnet\sdk\2.2.105\Microsoft.Common.CurrentVersion.targets(4194,5): error MSB3021: Unable to copy file "obj\Release\netcoreapp2.1\BVData.dll" to "bin\Release\netcoreapp2.1\BVData.dll". Access to the path '...\BVData\bin\Release\netcoreapp2.1\BVData.dll' is denied. [...\BVData\BVData.csproj]

I am unable to determine who has "bin\Release\netcoreapp2.1\BVData.dll" locked.

How can I diagnose this?

@genifycom
Copy link
Author

This one is also very common (i.e. failed to write to csproj.FileListAbsolute.txt). Diagnostics provides no additional information.

C:\Program Files\dotnet\sdk\2.2.105\Microsoft.Common.CurrentVersion.targets(5106,5): error MSB3491: Could not write lines to file "obj\Release\netcoreapp2.1\win-x64\BVTagging.csproj.FileListAbsolute.txt". The process cannot access the file '...\BVTagging\obj\Release\netcoreapp2.1\win-x64\BVTagging.csproj.FileListAbsolute.txt' because it is being used by another process. [...\BVTagging.csproj]

@karelz
Copy link
Member

karelz commented Mar 30, 2019

Is it a problem specific to your solution, or are you able to reproduce it on small solution / repro as well?

Antiviruses are often known to lock files, can you check if that is the case for you? Windows tool to check is e.g. Process Monitor: https://docs.microsoft.com/en-us/sysinternals/downloads/procmon

@karelz karelz added the needs-more-info Not enough information has been provided. Please share more detail as requested. label Mar 30, 2019
@genifycom
Copy link
Author

Thanks karlz. Not running any anti virus. Standard Windows development environment. I will try to reproduce on something smaller. But this is getting critical to production.

This one is also very common:

... publish: C:\Program Files\dotnet\sdk\2.2.105\Microsoft.Common.CurrentVersion.targets(2110,5): warning MSB3088: Could not read state file "obj\Debug\netcoreapp2.1\BVData.csprojAssemblyReference.cache". The process cannot access the file '...\BVData\obj\Debug\netcoreapp2.1\BVData.csprojAssemblyReference.cache' because it is being used by another process. [...\BVData.csproj]

So far tried dotnet publish 10 times this morning. Each time it fails on a different issue.

@karelz
Copy link
Member

karelz commented Mar 30, 2019

@genifycom try a small HelloWorld. If that works, chop off pieces of your projects to find out what triggers it.
Try it on brand new VM to see if it is one machine problem, or general problem with your solution.

If it is critical for your production, then I recommend to try lots of things in parallel to narrow down what is the problem.

@karelz
Copy link
Member

karelz commented Apr 11, 2019

No response, closing. Feel free to reopen when there's more info. Thanks!

@karelz karelz closed this as completed Apr 11, 2019
@genifycom
Copy link
Author

This is certainly not on one machine. All developers are getting it using this solution.

This is extremely difficult to isolate. It is 7 class libraries and one ASP.NET Core with dependencies between the class libraries and the ASP.NET

The problem here is dotnet publish verbose gives no additional information. Is there ANY other way to debug what is going on?

It happens seemingly randomly on different files.

@karelz
Copy link
Member

karelz commented May 29, 2019

Process Monitor is your best hope: #2524 (comment) ... as mentioned above.

@beachwalker
Copy link

beachwalker commented Mar 26, 2020

I have this issue, too. Looks like if the solution gets bigger and the parallel build is running?
If I run this several times not always the same projects are telling this warning.

This happens to me only if I call dotnet publish to the solution instead of a specific project inside the solution.

I use a common output directory. Here are the .csproj settings:

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <LangVersion>8.0</LangVersion>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <OutputPath>$(ProjectDir)..\..\build</OutputPath>
    <OutDir>$(OutputPath)</OutDir>
    <UseCommonOutputDirectory>True</UseCommonOutputDirectory>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
    <OutputPath>$(ProjectDir)..\..\build</OutputPath>
    <OutDir>$(OutputPath)</OutDir>
    <UseCommonOutputDirectory>True</UseCommonOutputDirectory>
  </PropertyGroup>

… from the output:

C:\Program Files\dotnet\sdk\3.1.201\Microsoft.Common.CurrentVersion.targets(4183,5): warning MSB3026: "obj\Release\netcoreapp3.1\win10-x64\Arena.Framework.Presentation.dll" konnte nicht in "..\..\build\Arena.Framework.Presentation.dll" kopiert werden. Wiederholung 1 wird in 1000 ms gestartet. The process cannot access the file 'C:\Users\thoma\source\repos\Arena\build\Arena.Framework.Presentation.dll' because it is being used by another process. [C:\Users\thoma\source\repos\Arena\src\Arena.Framework.Presentation\Arena.Framework.Presentation.csproj]

Anyway, the publish output seems to be fine… looks like a retry is made and succeeds.

p.s. AV is off here, too. Win10 VS2019, dotnet 3.1

@rikkigouda
Copy link

Please open this back up. I'm running a sample hello world solution targeting netcoreapp3.1 on Microsoft hosted agent (Hosted Windows 2019 with VS2019), same issue when calling dotnet publish.

How was this issue closed?

@rikkigouda
Copy link

More info on the build error log:

Unable to use package assets cache due to I/O error. This can occur when the same project is built more than once in parallel. Performance may be degraded, but the build result will not be impacted.
C:\Program Files\dotnet\sdk\3.1.300\Microsoft.Common.CurrentVersion.targets(2081,5): warning MSB3088: Could not read state file "obj\Release\netcoreapp3.1\helloworldaspnetcore.csprojAssemblyReference.cache". Access to the path 'C:\app\obj\Release\netcoreapp3.1\helloworldaspnetcore.csprojAssemblyReference.cache' is denied. [C:\app\helloworldaspnetcore.csproj]
C:\Program Files\dotnet\sdk\3.1.300\Microsoft.Common.CurrentVersion.targets(2081,5): warning MSB3101: Could not write state file "obj\Release\netcoreapp3.1\helloworldaspnetcore.csprojAssemblyReference.cache". Access to the path 'C:\app\obj\Release\netcoreapp3.1\helloworldaspnetcore.csprojAssemblyReference.cache' is denied. [C:\app\helloworldaspnetcore.csproj]
C:\Program Files\dotnet\sdk\3.1.300\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.GenerateAssemblyInfo.targets(119,5): error MSB3491: Could not write lines to file "obj\Release\netcoreapp3.1\helloworldaspnetcore.AssemblyInfoInputs.cache". Access to the path 'C:\app\obj\Release\netcoreapp3.1\helloworldaspnetcore.AssemblyInfoInputs.cache' is denied. [C:\app\helloworldaspnetcore.csproj]
C:\Program Files\dotnet\sdk\3.1.300\Microsoft.Common.CurrentVersion.targets(5199,5): error MSB3491: Could not write lines to file "obj\Release\netcoreapp3.1\helloworldaspnetcore.csproj.FileListAbsolute.txt". Access to the path 'C:\app\obj\Release\netcoreapp3.1\helloworldaspnetcore.csproj.FileListAbsolute.txt' is denied. [C:\app\helloworldaspnetcore.csproj]
The command 'cmd /S /C dotnet publish -c Release -o out' returned a non-zero code: 1

@karelz
Copy link
Member

karelz commented May 30, 2020

This issue was closed due to not enough information -- see above: #2524 (comment)

In general we do not monitor closed bugs - especially when closed for 1+ year. I would recommend to create a new one.
Given that this is not reproducible internally and only small number of people hit it, I recommend to collect ProcessMonitor traces to see what is going on on your machine and if some SW interacts there ... see #2524 (comment)

@DrFisheur
Copy link

I had the same problem, and, i'm throwing a wild guess here, it seems to me that some files are held by a cache of some sort. For my case, the files that i couldn't delete (even through FTP) were the main app dll and the first referenced view dll. Only after deleting all the files through FTP that i was able to delete the two faulty files.
After all that, i was able to republish the new build.
One thing to note though, i am publishing on a distant web server and not on my development machine.
I use asp.net core 3.1 and server side blazor with VS 2019 v 16.8.4 on Windows 10 64 bits.

@dotnet dotnet locked and limited conversation to collaborators Feb 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs-more-info Not enough information has been provided. Please share more detail as requested.
Projects
None yet
Development

No branches or pull requests

5 participants