dotnet / msbuild

The Microsoft Build Engine (MSBuild) is the build platform for .NET and Visual Studio.
https://docs.microsoft.com/visualstudio/msbuild/msbuild
MIT License
5.22k stars 1.35k forks source link

Build fails when signing #3523

Open JohanLarsson opened 6 years ago

JohanLarsson commented 6 years ago

Steps to reproduce

https://github.com/JohanLarsson/SignRepro

Actual behavior

CSC : error CS7027: Error signing output with public key from file 'SignRepro.snk' -- The process cannot access the file because it is being used by another process. (Exception from HRESULT: 0x80070020)

I'm getting ^ when doing rebuild from visual studio. Have rebooted and getting it on two real slns that worked yesterday. Updated Visual Studio yesterday.

Environment data

msbuild /version: 15.7.180.61344 image

Windows 7 64.

JohanLarsson commented 6 years ago

Works fine on Win 10.

JohanLarsson commented 6 years ago

Updated VS on another Win 7 machine and it builds fine. Closing this as it is probably some weird issue on my machine.

JohanLarsson commented 6 years ago

I managed to repro this when installing 3DxWare 10 for Windows (64-bit) 10.5.8 from here: https://www.3dconnexion.eu/service/drivers.html

After install & reboot I got the issue on the other machine but only once out of maybe 20 rebuilds.

JohanLarsson commented 6 years ago

I used procmon and nothing is locking the snk which is weird if the driver is the culprit. Renaming the snk works so not locked.

rainersigwald commented 6 years ago

Your repro project works on my machine, but I didn't try it many times. Looking at the Roslyn repo (since the compiler itself is throwing this error), I see some possibly-related reports: https://github.com/dotnet/roslyn/issues/17812 and https://github.com/dotnet/roslyn/issues/26232. Do you think you could add some information to them?

I agree that that driver would be a confusing culprit. Are you running antivirus? That can sometimes cause confusing file-locked issues.

JohanLarsson commented 6 years ago

I tried it on three machines today. One fails on every rebuild of the repro project. Build works. I tried setting MSBUILDDISABLENODEREUSE=1 but still 100% failures. I updated VS and installed the driver on another machine and got one repro for maybe 50 attempts today. Both are Win 7 with the same antivirus. I can't disable antivirus on the computers ate work, at least I don't know how to do it but I do know I'm not supposed to :)

And yes, the issues you linked look like the same issue.

On a win 10 machine without antivirus and no driver it has worked every time. @eyalsk cloned the repo and ran a large number of builds using a script with 100% successrate.

JohanLarsson commented 6 years ago

I used Autodesk Inventor today, first time in a long time. Used it on the machine with 100% failing rebuilds. Only used it in the morning and did many reboots during the day.

iam3yal commented 6 years ago

Just for the record I ran this with the following configuration:

  1. i7-8700k clocked at 5Ghz.
  2. Windows 10 Pro.
  3. msbuild v15.7.180.61344.

The powershell script I used is this: (initially ran it up to 50 times)

Clear-Host

For ($i = 0; $i -le 1000; $i++) {
    Start-Process "msbuild" -ArgumentList "/t:rebuild /m" -NoNewWindow -Wait
}
JohanLarsson commented 6 years ago

This https://developercommunity.visualstudio.com/content/problem/138889/vs2017-strong-name-signing-issue-with-antivirus-cs.html looks like the same issue but we are using McAfee

JohanLarsson commented 6 years ago

If I change to new project format rebuild works.

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net461</TargetFramework>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
  </PropertyGroup>

  <PropertyGroup>
    <SignAssembly>true</SignAssembly>
    <AssemblyOriginatorKeyFile>SignRepro.snk</AssemblyOriginatorKeyFile>
  </PropertyGroup>
</Project>
JohanLarsson commented 6 years ago

My current suspicion is that installing the VS 15.7.5 update messed up my machine somehow. Been having this issue after the restart the day after the update.