11

Build error is occurring since using Visual Studio 2015. When building in Visual Studio 2015 this is occurring rarely. When building in TeamCity this occurs very often.

[Error in Visual Studio 2015]

  • Error extracting public key from file 'CompanyName.snk': The process cannot access the file 'C:\Users\UserName\AppData\Local\Temp\tmp2FF6.tmp' because it is being used by another process. CompanyName.Project.DAL D:\Projecten\CompanyName\Repository\Source\Components\CompanyName.Project.DAL\vbc

https://i.stack.imgur.com/hKbbe.png

[Error in TeamCity]

  • CSC error CS7027: Error signing output with public key from file 'CompanyName.snk' -- The process cannot access the file 'C:\BuildAgents\Gamma\temp\buildTmp\tmpD91D.tmp' because it is being used by another process.

https://i.stack.imgur.com/rbgHx.png

Bart VdA
  • 578
  • 1
  • 5
  • 15
  • 1
    It looks like the problem with multicore build. Have you tried to build your solution with single instance of MSBuild (without /m switch)? Have you tried to diagnose the detailed output log of MSBuild? Have you tried to determine which process own the temp file? – stukselbax Oct 08 '15 at 07:16
  • I've started seeing this issue on our Jenkins build server within the last week! I use 4 cores (/m:4) when building. It seems to happen at random and with different projects every time. I've never had the error locally. Only from the build server. – llykke Nov 27 '15 at 09:04
  • Started seeing this all of a sudden in our build server, and it turned out to be a recent update (July 2020) to Windows Defender, see my comment [here](https://stackoverflow.com/a/51603715/63209). – Paul Jul 22 '20 at 21:53

8 Answers8

13

I know it's been a while since this was asked but as I use SO for my own reference and I had this problem too I wanted to share my solution.

.snk files are for signing a project. You might need to make a new one.

  • Right click on your project, select properties.
  • Click on Signing.
  • Click the checkbox beside "Sign the assembly".
  • On the dropdown labelled "Choose a strong name key file" click new.
  • Fill in the dialog box as you wish noting particularly the Key file name. When you press ok, this will generate a new .snk file.
  • Save the project and rebuild.
  • This will use the new .snk in your project and will resolve the error.

Hope this helps.

Francis Rodgers
  • 4,565
  • 8
  • 46
  • 65
  • 1
    Will give it a try, for now I just removed the signing on the project. Also solved it as a workaround :-) – Bart VdA Aug 07 '16 at 11:51
4

Try to clean up the temp folder that is used by the build. I have seen different types of problems when the temp folder has lots of files.

Some of the tools are using GetTempFileName and they will get errors when temp has a lots of files

The GetTempFileName method will raise an IOException if it is used to create more than 65535 files without deleting previous temporary files.

Alexander Bartosh
  • 8,287
  • 1
  • 21
  • 22
  • The amount of files in the temp folders of the agent are limited. Is this the temp folder you are referring to? – Bart VdA Feb 17 '16 at 11:10
  • Was exactly this. The temp folder for the user running the build (`C:\Users\USERNAME\AppData\Local\Temp`) was having more than 65535 files. – Alex M Feb 23 '16 at 15:22
2

This is probably an instance of this issue with Roslyn compiler. The workaround would be adding

<UseSharedCompilation>False</UseSharedCompilation>

under any <PropertyGroup> node in .csproj file.

n0rd
  • 11,850
  • 5
  • 35
  • 56
0

It started for me when I moved the Resharper Cache to System Temp. When I moved it back to the Solution folder, the problem went away, and I could build again.

Brian
  • 1,845
  • 1
  • 22
  • 37
0

I just had the same problem. In Visual Studio 2015, I fixed it using the following steps:

  1. Go to Tools > Options
  2. From the Options dialog, select "Projects and Solutions > Build and Run"
  3. Set the "maximum number of parallel project builds" to 1

+1 to @stukselbax for getting me on the right track Also got help from this link

Mark Bell
  • 384
  • 2
  • 8
0

I used '/m:1' as an msbuild argument, and 'SignPublic' property to true in the csproj file.

0

Just had this issue today in visual Studio 2022- I was messing with the csproj file and ended up having the wrong filepath to the snk file. I fixed it by changing the filepath to be correct.

  1. Right-click on the project -> unload (so that you can edit the csproj file)

  2. Under <PropertyGroup> check the <AssemblyOriginatorKeyFile> tag

  3. My code was:<SignAssembly>true</SignAssembly> <AssemblyOriginatorKeyFile>../NAMEHERE.snk</AssemblyOriginatorKeyFile> NAMEHERE was specific to my project, yours will vary. Look at your snk file. The ../ in front will vary, check the filepath of your snk file. If you caused this error by messing with your csproj file, like I did, then the correct answer is what the filepath was before you changed it. :)

  4. Right-click on the project -> reload

0

double click on your project and set to false:

  <SignAssembly>false</SignAssembly> 
 <PublicSign>false</PublicSign>

remove this line :

 <AssemblyOriginatorKeyFile>CompanyName.snkk</AssemblyOriginatorKeyFile>