When using MSBuild.ILMerge.Task referenced via packagereference the following error came up:
error MSB4018: The "MSBuild.ILMerge.Task" task failed unexpectedly.
error MSB4018: System.IO.FileNotFoundException: Cannot find ILMerge
executable.
error MSB4018: at MSBuild.ILMerge.Task.LoadILMerge()
error MSB4018: at MSBuild.ILMerge.Task.Execute()
error MSB4018: at error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()
This is because the MSBuild.ILMerge.Task.dll can't find the ILMerge executable in its package location. I guess the main reason of this may be the different folder structure between package.config and PackageReference.
Has anyone else had this issue? Any help is appreciated in advance
You could try downgrading ILMerge to 2.14.1208.
This solved it for me.
https://github.com/emerbrito/ILMerge-MSBuild-Task/issues/13
I had the same problem. In my case it arose due to the following reasons (related to some updates in my Nuget packages):
sometimes I had few conditions in my project files to handle Nuget packages. When ever I updated my Nuget packages, these project files were updated and all my conditions were overwritten. I found this issue by using diff tools in Git and add my conditions manually then everything was working fine.
Again sometimes I need to update my Nuget packages (my solution includes multiple dependent projects, so I need to update my Nuget packages when I build a new version). If I forgot to commit my changes in Git (including package.config and project files) the same issues appeared (in release mode).
Related
For some reason GitHub Actions is not pulling in one Nuget package ConfigCat.Client but works fine for the remaining 20 packages. This is one solution with many projects. It works fine in VS Build as well as local msbuild command. I have another simple solution in GitHub Actions that works fine as well. I'm using a win-2019 server runner with .NET SDK 5.0. I get:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2203,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "ConfigCat.Client, Version=6.5.2.0, Culture=neutral, PublicKeyToken=d28b16a067d7bbe2, processorArchitecture=MSIL". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
I'm running this (restore & build):
msbuild $env:Solution_Path /t:Restore /p:Configuration=$env:Configuration /p:RuntimeIdentifier=$env:RuntimeIdentifier
msbuild $env:Solution_Path /p:Platform="Any CPU" /p:Configuration=Release /p:UapAppxPackageBuildMode=SideloadOnly /p:AppxBundle=Always /p:PackageCertificateKeyFile=$certificatePath /p:PackageCertificatePassword=${{ secrets.Pfx_Key }}
Errors from log file (could it be related to processorArchitecture=MSIL?)
2022-08-28T03:05:23.6891561Z Primary reference "ConfigCat.Client, Version=6.5.1.0, Culture=neutral, PublicKeyToken=d28b16a067d7bbe2, processorArchitecture=MSIL".
2022-08-28T03:05:23.6894672Z C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2203,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "ConfigCat.Client, Version=6.5.1.0, Culture=neutral, PublicKeyToken=d28b16a067d7bbe2, processorArchitecture=MSIL". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. [D:\a\DataProduction\DataProduction\BigLebowski\Services\FeatureFlagService\FeatureFlagService.csproj]
2022-08-28T03:05:23.6896617Z For SearchPath "{HintPathFromItem}".
2022-08-28T03:05:23.6897448Z Considered "D:\a\DataProduction\DataProduction\BigLebowski\packages\ConfigCat.Client.6.5.1\lib\net45\ConfigCat.Client.dll", but it didn't exist.
I've also tried changing the Platform to x64 with the same results.
Any insight or pointers is greatly appreciated.
Thanks to Péter Csajtai for solving the problem. The project was using packages.config and not restoring the nuget package as a result. Adding the parameter /p:RestorePackagesConfig=true to the restore resolved the issue. See also this question.
In one of my VS 2017 instance, the same solution would required a shut down and rebuild when editing a cshtml file during debug. I have search google for a few days now and cannot find a solution.
This is the error:
An error occurred during the compilation of a resource required to process this request. Please review the following specific error details and modify your source code appropriately.
Generated Code
The type 'PartialTagHelper' exists in both 'Microsoft.AspNetCore.Mvc.TagHelpers, Version=2.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' and 'Microsoft.AspNetCore.Mvc.TagHelpers, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
Check your NuGet dependencies and dependencies of the dependencies to figure out which of them is dependent on version 2.1.0.
As for fixing the issue there are the following options:
Update all the Microsoft.* NuGetpackages to 2.1.1 - should fix the
problem.
Or clean up the build outputs, NuGet cache, and delete .vs folder to
avoid any caching issues and then - rebuild again. If won't help,
get the repository sources to new directory from scratch.
This sample shows a .NET Core project which can be packaged into a nuget package just using dotnet pack, and when restored in another project, it integrates in the msbuild pipeline. One of the great things about this sample is it creates a nuget package that integrates with msbuild on linux, mac and Windows. However, the custom build code doesn't have dependencies on any other assemblies.
How can I adapt this sample to use code that uses a dependency?
Here are my failed attempts:
Attempt 1
I added a package reference to Newtonsoft.Json and changed the code to do some JSON serialisation. However, in the project that uses the build nuget, when I do a dotnet publish, I get the following error:
error MSB4018: The "Zip" task failed unexpectedly. [C:\git\MSBuild-Features-With-Nate-McMaster\Video-2\1-NuGet\Web.csproj]
error MSB4018: System.IO.FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'. The system cannot find the file specified. [C:\git\MSBuild-Features-With-Nate-McMaster\Video-2\1-NuGet\Web.csproj]
Additionally, if my project didn't already have a dependency on JSON.NET, adding the build nuget would unnecessarily add it.
Attempt 2
I used nuget.exe spec to create a .nuspec file. At the end of the file, I added:
<files>
<file src="bin\Release\**" target="build" />
<file src="build\**" target="build" />
</files>
However, both "dotnet pack" and "msbuild /t:pack" ignore the file, and nuget.exe pack fails with the error Unable to find 'bin\Release\0-WriteATask\bin\Release\'. Make sure the project has been built..
If I try nuget.exe pack Zipper.nuspec or msbuild /t:pack /p:NuspecFiles=Zipper.nuspec, they both fail with the message Value cannot be null or an empty string..
Attempt 3
I edited the nuspec to remove all of the placeholders that are normally calculated from the project (any string starting and ending with a $). Then, doing a nuget.exe pack Zipper.nuspec created a nupkg file, and the net46 folder contains Newtsonsoft.Json.dll, but the netstandard1.3 folder does not.
The way MSBuild loads a task assembly can make it tricky to load additional assemblies that you may depend on.
Typically, the easiest way to solve this is to ship a copy of your dependencies inside your NuGet package. But your dependencies alongside your task assembly file in the package. There may be some additional complications that require you to use AssemblyLoadContext or the AppDomain.AssemblyResolve event.
You can do this without a nuspec file by forcing MSBuild to copy your assemblies into the local build output, and then copying them into your package. Set CopyLocalLockFileAssemblies=true, and add the items to _PackageFiles
Here's an example of how to do that: https://github.com/madskristensen/BundlerMinifier/blob/3333b5c38289a247391966443370ee6f4a29bf26/src/BundlerMinifier/BundlerMinifier.csproj#L35-L47
Hopefully, this will be addressed in the future, https://github.com/Microsoft/msbuild/issues/1312, and the task assembly resolution will use the NuGet cache.
Try it with the 9.0.1 version of Newtonsoft.Json, it worked for me, all these dll load problems went away, and it still targets .NET Standard. Although I did copy all the dependencies next to the task dll, but with the 10.x version even that didn't help.
I just upgraded my Visual Studio to the latest version (1/30/2017).
My ASP.NET Core project was working before the upgrade, but I now get the following error that stops me. Are there any simple solutions to this?
Severity Code Description Project File Line Suppression State
Error MSB4018 The "ResolvePackageDependencies" task failed unexpectedly.
System.IO.FileNotFoundException: Could not load file or assembly 'System.IO.FileSystem, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
File name: 'System.IO.FileSystem, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
at Microsoft.NET.Build.Tasks.LockFileCache.LoadLockFile(String path)
at Microsoft.NET.Build.Tasks.LockFileCache.GetLockFile(String path)
at Microsoft.NET.Build.Tasks.ResolvePackageDependencies.get_LockFile()
at Microsoft.NET.Build.Tasks.ResolvePackageDependencies.ReadProjectFileDependencies()
at Microsoft.NET.Build.Tasks.ResolvePackageDependencies.ExecuteCore()
at Microsoft.NET.Build.Tasks.TaskBase.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()
In my particular case, I did a Clean Solution, Tools/options/NuGet Package Manager/Clear All NuGet Cache(s), then a reboot. Loading/building the project then worked.
Not sure how repeatable this is. I'm quite sure my project worked the first time I loaded it, then failed, then worked again after these steps. It has worked on 2 computers.
I solved this by running dotnet build in the Paket-Manager Console of VS Studio.
After the software was again debuggable
The easiest way to fix this is to create a new ASP.NET Core application, check its .csproj file and modify the old project based on it. A lot of things seem to have been removed and simplified and it's too much to list here.
I've written a custom task for analyzing code coverage results. While building the entire solution, I get the following error.
error MSB4018: System.IO.FileNotFoundException: Could not load file or
assembly 'Microsoft.VisualStudio.Coverage.Analysis, Version=9.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find
the file specified.
I checked the path specified during the build process and the dll location is correct. Yet, i get a FileNotFoundException.
Am I missing something?
Thanks...
This may sound like a silly suggestion, but have you checked that you're running the Visual Studio 200X Command Prompt and not the Visual Studio 200X x64 Cross Tools Command Prompt ?
I managed to fix the problem. I had to add the assembly to the GAC using gacutil.exe. The error vanished once the assembly was added.