1

I have complex solution with a lot of MVC web application projects which have to be built in a specific way. That's why I use custom build project and msbuild utility to build the solution on my local machine. The thing is that the solution and all projects in it are building successfully in Visual Studio. But when I try to build the solution via msbuild using AspNetCompiler I keep getting the same error:

ASPNETCOMPILER : error ASPCONFIG: Could not load file or assembly 'Duke.Owin.VkontakteMiddleware, Version=1.2.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

This error does not appear when I build solution in Visual Studio (2013). Trying to fix the problem I've already done the following:

  1. All existing references in the projects of my solution are configured to Copy local = true
  2. Before each build I clear (and remove) all bin and obj folders of my projects.
  3. I cleared Temporary Asp .Net files multiple times and before each build.
  4. All assemblies, which compiler says it can't find, are located in packages folder.
  5. Tried to restore NuGet packages before each build:

    • Downloaded NuGet
    • Enabled NuGet package restore by adding EnableNuGetPackageRestore=true environment variable
    • Added <Exec Command='$(ToolsDirectory)\nuget restore "$(Solution)"'/> command to my build project.
  6. Tried manually define references in build project: <ItemGroup><Reference Include="Duke.Owin.VkontakteMiddleware"><HintPath>$(PackagesFolder)\Duke.Owin.VkontakteMiddleware.1.2.0.0\lib\net45\Duke.Owin.VkontakteMiddleware.dll</HintPath></Reference></ItemGroup>

  7. As it is suggested here, I manually edited the project file that is failing to build and added <Private>True</Private> in each Reference node that isn't found by compiler.

  8. Tried manually copy missed dlls: <Copy SourceFiles="$(PackagesFolder)\Duke.Owin.VkontakteMiddleware.1.2.0.0\lib\net45\Duke.Owin.VkontakteMiddleware.dll" DestinationFolder="$(OutputDirectory)\bin" SkipUnchangedFiles="true" />

But, after all of the above, still no luck. Are there any more solutions?

UPDATE: If I add the assembly to GAC it actually helps, BUT some of my assemblies are installed packages from the nuget and they are not strongly named so I can't add all of them to the GAC. And, of course, registering all assemblies in the GAC is not a desirable solution.

Community
  • 1
  • 1
Dmytro
  • 14,708
  • 24
  • 70
  • 120
  • This is a common issue where one is using a build environment located somewhere else. The bottom line is that build machine itself must have access to all the DLLS your local machine has. Typically this means the build machine will either need to install those dlls or you will have to include them in your assembly. Who is referencing this one? Duke.Owin.VkontakteMiddleware and where is it found on your local machine? – JWP Jan 11 '16 at 23:40
  • @JohnPeters, I am performing the build on my local machine. I do not have any build servers. This dll is located in packages folder of my solution and is referenced by one of the projects. – Dmytro Jan 11 '16 at 23:43
  • Have you tried using NuGet to restore the solution packages before running msbuild? `nuget restore MySolution.sln` – Diego Jan 12 '16 at 00:25
  • If you are still having this problem you can debug it using the Fusion Log. Just because a Dll is on the system, doesn't mean the loader can find it or other dependent assemblies in it. – JWP Jan 24 '16 at 17:35

1 Answers1

1

See Common Issues With Automatic Package Restore, which reads:

For a custom build .proj, a pre build <Exec> action to restore nuget packages is required. This is not added automatically.

Hope that helps.

Diego
  • 16,895
  • 5
  • 56
  • 64
  • Thanks, I've tried this... it didn't help. I get "All packages listed in packages.config are already installed." message when try to restore packages before the build. Still get the same error. – Dmytro Jan 12 '16 at 10:21