Octopack msbuild task fails to set version properly with web application that contains nuget packages

octopack msbuild task fails to set version properly with web application that contains nuget packages, because it can’t load the types from the web assembly, and can’t find the gitversion type

I debuged the msbuild task, and it is failing here on line 27 https://github.com/OctopusDeploy/OctoPack/blob/3.6.1/source/OctoPack.Tasks/Util/AssemblyExtensions.cs

This is fairly easy to reproduce with simple console app. try loading the pirmary assembly from an external web project and it will work fine when calling Assembly.GetTypes().

However, do the same thing but add a nuget reference to the web project (like json.net) and it will fail, because Assembly.Load is looking for newtonsoft.json in the msbuild directory and not the web application directory.

Here is the output from the msbuild log

Using “GetAssemblyVersionInfo” task from assembly “C:\git\OctoPack\source\OctoPack.Tasks\bin\Debug\OctoPack.Tasks.dll”.
Task "GetAssemblyVersionInfo"
OctoPack: Get version info from assembly: C:\git\FooBar\Foo.Bar.Web\bin\Foo.Bar.Web.dll
OctoPack: Could load GitVersion information from the assembly at path C:\git\FooBar\Foo.Bar.Web\bin\Foo.Bar.Web.dll.
OctoPack: System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.RuntimeModule.GetTypes()
at System.Reflection.Assembly.GetTypes()
at AssemblyExtensions.GetNugetVersionFromGitVersionInformation(Assembly assembly) in C:\git\OctoPack\source\OctoPack.Tasks\Util\AssemblyExtensions.cs:line 27
at OctoPack.Tasks.GetAssemblyVersionInfo.GetNuGetVersionFromGitVersionInformation(String path) in C:\git\OctoPack\source\OctoPack.Tasks\GetAssemblyVersionInfo.cs:line 141
at OctoPack.Tasks.GetAssemblyVersionInfo.UseNuGetVersionFromGitVersionInformation(String path, FileVersionInfo info) in C:\git\OctoPack\source\OctoPack.Tasks\GetAssemblyVersionInfo.cs:line 69
at OctoPack.Tasks.GetAssemblyVersionInfo.CreateTaskItemFromFileVersionInfo(String path) in C:\git\OctoPack\source\OctoPack.Tasks\GetAssemblyVersionInfo.cs:line 56
Done executing task “GetAssemblyVersionInfo”.

Here is the output from the fusion logger for one of the assemblies that fails to load

*** Assembly Binder Log Entry  (7/20/2017 @ 12:57:44 PM) ***

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\bin\MSBuild.exe
— A detailed error log follows.

=== Pre-bind state information ===
LOG: DisplayName = Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
(Fully-specified)
LOG: Appbase = file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/MSBuild/15.0/bin/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = MSBuild.exe
Calling assembly : (Unknown).

LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\bin\MSBuild.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/MSBuild/15.0/bin/Newtonsoft.Json.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/MSBuild/15.0/bin/Newtonsoft.Json/Newtonsoft.Json.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/MSBuild/15.0/bin/Newtonsoft.Json.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/MSBuild/15.0/bin/Newtonsoft.Json/Newtonsoft.Json.EXE.
LOG: All probing URLs attempted and failed.

*** Assembly Binder Log Entry  (7/20/2017 @ 12:57:44 PM) ***

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\bin\MSBuild.exe
— A detailed error log follows.

=== Pre-bind state information ===
LOG: DisplayName = Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
(Fully-specified)
LOG: Appbase = file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/MSBuild/15.0/bin/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = MSBuild.exe
Calling assembly : (Unknown).

LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\bin\MSBuild.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/MSBuild/15.0/bin/Newtonsoft.Json.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/MSBuild/15.0/bin/Newtonsoft.Json/Newtonsoft.Json.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/MSBuild/15.0/bin/Newtonsoft.Json.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/MSBuild/15.0/bin/Newtonsoft.Json/Newtonsoft.Json.EXE.
LOG: All probing URLs attempted and failed.

Hi Erick,

Would you be able to send through your FooBar solution so I can repro, and maybe your full msbuild log?

Regards,
Mark

Hi,
i think i have a similar problem:
Octopack 3.6.1, msbuild 15 :
(OctoPack target) ->
C:\onwms\src\OnWms\packages\OctoPack.3.6.1\build\OctoPack.targets(47,29): err
or MSB4064: The “UseFileVersion” parameter is not supported by the “GetAssembly
VersionInfo” task. Verify the parameter exists on the task, and it is a settabl
e public instance property.
C:\onwms\src\OnWms\packages\OctoPack.3.6.1\build\OctoPack.targets(47,5): erro
r MSB4063: The “GetAssemblyVersionInfo” task could not be initialized with its
input parameters.

How did you solve the issue ?
Thanks

Hi,

Thanks for getting in touch. This usually happens because you have a new version of the OctoPack.targets file (3.6.1 in your case), which is supplying the UseFileVersion parameter, but MSBuild is finding an old version of the OctoPack dll, which doesn’t support this new parameter. You can take a look at previous discussion here on a similar issue (although with different versions of OctoPack) https://help.octopusdeploy.com/discussions/problems/44005-teamcity-octopack-package-version-appendtoversion.

Essentially make sure all projects in your solution have the same version of OctoPack, and clean out the build folder on your build server. MSBuild will also hold dlls in memory and reuse them, so it’s possible it is caused by a different solution being built and having its OctoPack version loaded and kept around by MSBuild (See Scott Brickley’s great response in the linked thread).

Newer versions of OctoPack print out their version number when running tasks, so you may see that somewhere else in you build log.

Regards,
Mark

Thanks !
I was it, i forgot it was referenced in another project :smiley: