Xamarin Android linking cannot access file : <p>I have a Xamarin Android project that I am trying to use Sdk and User Assembly linking with.</p>

<p>If I set the Android project to Sdk Assembly Linking only, the APK is created and deployed successfully and works.</p>

<p>However, when I set Sdk and User Assembly linking, with no other changes, I get the following error <em>only</em> when I deploy. The solution builds succesfully.</p>

<pre><code>The "LinkAssemblies" task failed unexpectedly.    
System.IO.IOException: The process cannot access the file '&lt;path-to-project&gt;\AppName\AppName.Android\obj\Release\android\assets\AppName.Core.dll' because it is being used by another process.
    at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
    at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
    at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
    at Mono.Cecil.ModuleDefinition.Write(String fileName, WriterParameters parameters)
    at Mono.Linker.Steps.OutputStep.WriteAssembly(AssemblyDefinition assembly, String directory)
    at Mono.Linker.Steps.OutputStep.OutputAssembly(AssemblyDefinition assembly)
    at Mono.Linker.Steps.OutputStep.ProcessAssembly(AssemblyDefinition assembly)
    at Mono.Linker.Steps.BaseStep.Process(LinkContext context)
    at Mono.Linker.Pipeline.Process(LinkContext context)
    at MonoDroid.Tuner.Linker.Process(LinkerOptions options, LinkContext&amp; context)
    at Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res)
    at Xamarin.Android.Tasks.LinkAssemblies.Execute()
    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
    at Microsoft.Build.BackEnd.TaskBuilder.&lt;ExecuteInstantiatedTask&gt;d__26.MoveNext()
</code></pre>

<p><code>AppName.Core.dll</code> is another library project in my solution that is set to build as NetStandard 2.0.</p>

<p>I have looked through many other bug reports and forum posts regarding a similar issue to this, but most seem related to an earlier bug with Visual Studio 15.5.1 that has since been fixed.</p>

<ul>
<li>The main Xamarin bug report is: <a href="https://bugzilla.xamarin.com/show_bug.cgi?id=56275" rel="noreferrer">https://bugzilla.xamarin.com/show_bug.cgi?id=56275</a> but was resolved in VS 15.2.</li>
<li>A forum topic (<a href="https://forums.xamarin.com/discussion/32976/updating-xamarin-broke-the-build-process-the-process-cannot-access-the-file-appname-dll-mdb" rel="noreferrer">https://forums.xamarin.com/discussion/32976/updating-xamarin-broke-the-build-process-the-process-cannot-access-the-file-appname-dll-mdb</a>) also talks about a similar issue being resolved in VS 15.5.1.</li>
<li>Other SO questions refer to older Xamarin or VS versions, or have unacceptable solutions (such as just turning off linking):

<ul>
<li><a href="https://stackoverflow.com/questions/44796380/the-link-assemblies-tasks-failed-unexpectedly-xamarin-forms">The Link Assemblies tasks failed unexpectedly Xamarin Forms</a></li>
</ul></li>
</ul>

<p>Regardless, I have tried just about every solution suggested in those links including:</p>

<ul>
<li>closing and reopening Visual Studio</li>
<li>deleting /bin and /obj folders</li>
<li>opening Visual Studio as Administrator</li>
<li>running MsBuild from a command prompt with VS closed</li>
</ul>

<p>As well as various combinations of the above.</p>

<p><a href="https://docs.microsoft.com/en-us/xamarin/cross-platform/deploy-test/linker" rel="noreferrer">My custom linker.xml</a> contains an exception for my library project:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
&lt;linker&gt;    
    ...    
    &lt;assembly fullname="AppName.Core" &gt;&lt;/assembly&gt;        
    ...        
&lt;/linker&gt;
</code></pre>

<p>As this point I seem to have exhausted all available options and am no closer to a workable solution. Suggestions on solutions, workarounds, or other debugging paths to follow would be most appreciated.</p>

<p>My Android Options config:</p>

<p><a href="https://i.stack.imgur.com/q6G6F.png" rel="noreferrer"><img src="https://i.stack.imgur.com/q6G6F.png" alt="Android Options"></a></p>

<p>Version Information:</p>

<ul>
<li>Visual Studio Version: 15.5.6</li>
<li>Xamarin Forms Version: 2.5.0.280555</li>
<li>Xamarin Version: 26.1.0.1</li>
</ul>
