NuGet dependency "Assembly specified...was not found" when running in IIS in development
Describe the bug
I am attempting to run a simple MVC web app under IIS in development. Using the "ASP.NET Core Web Application" template works as long as I either:
- do not add any NuGet references to it
- run it via
dotnet WebApplication1.dll
As soon as I both add a NuGet reference and run this from within IIS (the Windows feature, not express) I get the following error in the stdout log file:
Error:
An assembly specified in the application dependencies manifest (WebApplication2.deps.json) was not found:
package: 'SharpYaml', version: '1.6.4'
path: 'lib/netstandard2.0/SharpYaml.dll'
There are several other issues filed with a similar error, but most are describing problems with the lack of an SDK (confirmed that I have) and I can't find any about running under IIS.
To Reproduce
See this repo: https://github.com/collinsauve/AspNetCoreTest which includes web apps that are broken as well as the IIS applicationHost.config that I am using to host them in development. WebApplication1 was created using Rider WebApplication2 was created using VS2017
Steps to reproduce the behavior from scratch:
- Use VS2017 v15.9.4
- Create a new project
- Select Visual C# -> .NET Core -> ASP.NET Core Web Application
- Select "Web Application (Model-View-Controller)"
- Uncheck "Enable Docker Support"
- Select No Authentication
- Click OK
- Add this Web.config to the project.
- Target IIS shared config at this folder.
- Modify applicationHost.config so the app's absolute path points at the repo as needed.
- Modify
Program.csto use Kestrel - Build the project.
- Load
http://localhost. This should work. - Add a NuGet dependency to SharpYaml 1.6.4
- iisreset to kill the process
- Build the project again
- Load
http://localhost. This should NOT work.
Expected behavior
Web app loads without errors
Screenshots

Additional context
Here's a directory listing of the bin folder:
C:\code\AspNetCoreTest\WebApplication1\bin\Debug\netcoreapp2.2>dir
Volume in drive C is Windows
Volume Serial Number is 7E59-9AE7
Directory of C:\code\AspNetCoreTest\WebApplication1\bin\Debug\netcoreapp2.2
2018-12-31 03:17 PM <DIR> .
2018-12-31 03:17 PM <DIR> ..
2018-12-31 03:17 PM 235,242 WebApplication1.deps.json
2018-12-31 03:17 PM 10,240 WebApplication1.dll
2018-12-31 03:17 PM 1,840 WebApplication1.pdb
2018-12-31 03:17 PM 238 WebApplication1.runtimeconfig.dev.json
2018-12-31 03:17 PM 224 WebApplication1.runtimeconfig.json
2018-12-31 03:17 PM 66,048 WebApplication1.Views.dll
2018-12-31 03:17 PM 4,640 WebApplication1.Views.pdb
7 File(s) 318,472 bytes
2 Dir(s) 587,201,073,152 bytes free
Installed runtimes/sdks/frameworks/etc:

If I change the ApplicationPool to run under my user (instead of NetworkService) it works. Is this expected?
Since forcing developers to run IIS under their user accounts defeats the purpose of Shared Configuration (as it caused un-commitable changes in the git working directory), I needed another solution.
Adding <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> to the csproj causes all transitive dependencies, even SDK dependencies to be copied to the output folder. This fixes the problem and allows IIS to run under NetworkService, however the bin folder now includes > 180 files.
There's a hack/workaround for this mentioned on this issue and applied to my csproj which seems to copy NuGet packages but not SDK provided assemblies. bin folder is now only 8 files and includes the SharpYaml.dll.
This workaround will probably serve my needs. Closing issue.
For posterity/simplicity, here's the full workaround: add this to csproj:
<PropertyGroup>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
<!-- Remove files from copy local that would not be published as they are provided by the platform package -->
<Target Name="FilterCopyLocal" DependsOnTargets="RunResolvePublishAssemblies" BeforeTargets="ResolveLockFileCopyLocalProjectDeps">
<ItemGroup>
<_CopyLocalButNotPublished Include="@(AllCopyLocalItems)" Exclude="@(ResolvedAssembliesToPublish)" />
<AllCopyLocalItems Remove="@(_CopyLocalButNotPublished)" />
</ItemGroup>
</Target>
Excellent but I wouldn't recommend running from the bin folder. That is non standard.