I have Solution A which has a .NET Core 1.1 class library project. In the Package properties I filled all NuGet fields and selected to create the NuGet upon successful build. This project builds just fine and the NUPKG is created. BTW How can I automatically copy the generated NUPKG to a local directory (my own repository)?
Then I have Solution B which is an ASP.NET Core 1.1 web application. In it I browse to my local repository (where I have manually copied the NUPKG built by Solution A) and install my SolutionA.MyPackage into the web application. VS.2017 says it was successful at installing it. I see it listed in the project's NuGet dependencies.
However, when I try to use ANY of the objects defined in that NuGet package I get a red highlight saying it is not found as if there was no NuGet or assembly reference to that DLL but there is!
What is causing this Visual Studio generated Nuget package to be installed and yet act as if it has not even been referenced?
UPDATE - CSPROJ TARGET
As for copying to my local repository, I added this to CSPROJ but it was not working (somebody had suggested it as I put it). I finally figured out why it did not work, the ItemGroup must be inside the Task.
<Target Name="CopyPackage" AfterTargets="GenerateNuspec">
<ItemGroup>
<MyPackageFiles Include="bin\Release\PackageId.*.nupkg" />
</ItemGroup>
<Copy SourceFiles="#(MyPackageFiles)" DestinationFolder="D:\My Repository\MyNugget\Publish" />
</Target>
UPDATE NuGet Inspection
I opened the NUPKG with NuGet Package Explorer and it shows this more or less:
content\
Properties\
launchSettings.json
Views\
Shared\
rest of my stuff here
contentFiles\
any\
netcoreapp1.1\
Properties\
launchSettings.json
Views\
Shared\
rest of my stuff here
lib\
netcoreapp1.1 (.NEtCoreApp, Version=v1.1)
MyPackage.dll
UPDATE 3
Since NuGet seems to have stopped working (used to work well earlier) I opted for using an Assembly Reference rather than a NuGet (for now). In this situation something odd happens, when coding I can reference ALL the objects in the referenced assembly (former NuGet) and therefore no compilation errors on the main project BUT when I then run the web application I get an internal error because it says
FileNotFoundException: Could not load file or assembly
'MyPackage, Version=0.0.3.0, Culture=neutral, PublicKeyToken=null'.
The system cannot find the file specified.
Unknown location
Which is strange because in the Solution Explorer I see the assembly reference and when I click on it (main application) I can navigate to all the objects that I have defined in that assembly. Why it cannot find it anymore?
It is working again (as it was before!). Today I could open the solutions but when I tried to download an extension (Tools | Extensions) I got an error message about an Access Denied or something like that. It has happened before since I installed to VS.2017.
Of all the Visual Studios I have used since 2002 this has been the most unstable! (and I have update 15.2).
When I saw this error happening again I knew how to get rid of it and thought, "hey, maybe that is what is keeping the NuGet package to be installed but not found or the problem with a direct assembly reference".
So I went to my C:\Users\AppData\USER\Local\Microsoft\VisualStudio\15.2* folder and removed it completely.
After that I the ACCESS DENIED issue went away with the side effect that I had to reinstall all extensions again. I attempted again to install my own NuGet, it did so successfully and as expected (was not happening during the long glitch) the objects were found and the web application worked again.
Related
I have a project with assembly which refers to System.Threading.Tasks.Extensions, Version=4.6.28619, It's an old ASP.NET App hosted on IIS. After compilation, the app is running and everything is OK. After some time, the app throws an exception.
"System.Exception: Could not load file or assembly
'System.Threading.Tasks.Extensions, Version=4.1.0.0, Culture=neutral,
PublicKeyToken=cc7b13ffcd2ddd51.
After the recompilation and restarting the APP, everything works fine, but after a few hours, the exception is thrown again. What could be the problem?
I have tried to change web.config to use System.Threading.Tasks.Extensions in the correct version, but it didn't help.
Version=4.6.28619 is file version, not the Assembly Version. I did goodle on System.Threading.Tasks.Extensions history.
I found the 4.3.0 should be the correct version in your project.
Other version couldn't find 4.1.0.0 version dll like picture above. Package version >=4.4.0, using 4.1.1.0. <4.3.0, using 4.0.0.0.
Now you can follow the suggestions below to check the issue
Find the package System.Threading.Tasks.Extensions like my first picture.
If you have multi project, make sure all the projects using the same version package.
Delete the .vs folder
Check the web.confg/app.config file, and check the version of System.Threading.Tasks.Extensions, if there are duplicates, please delete them.
If the steps above not works for you, maybe the issue related to deployment. You can try the binding redirects.
I have a package config file for a project this
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Stylesoft.Common.Dev" version="1.0.1.0" targetFramework="net461" />
</packages>
And the package dll is referenced like this in csproj file
<Reference Include="Stylesoft.Common.Dev, Version=1.0.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\..\..\..\SharedPackages\Stylesoft.Common.Dev.1.0.1.0\lib\net40\Stylesoft.Common.Dev.dll</HintPath>
</Reference>
Earlier this used to work because nuget used to restore the package in this folder Stylesoft.Common.Dev.1.0.1.0 but I don't know what was changed but now nuget skip the revision number of version, now it creates folder with name Stylesoft.Common.Dev.1.0.1 skipping last zero and so I get compile error, because the project tries to check dll in this path
..\..\..\..\..\SharedPackages\Stylesoft.Common.Dev.1.0.1.0\lib\net40\Stylesoft.Common.Dev.dll
I am not able to figure out what was changed and how to make it restore package in the same folder structure as earlier
Any help would be appreciated!
I was suffering the same problem. The cause will either be that the nuget.exe version has been updated and now downloading packages excluding the revision in the path, or that a change has occurred where the packages are hosted. Not sure which for myself as this happened when migrating source from TFS to Azure DevOps. So the build pipeline is different and the packages are on a new feed.
I feel the best solution is to make the projects in Visual Studio work locally the same way the server build expects them to. So as it is looking for packages in folders excluding the revision number in their name, that's where they should be.
So the fix is to reinstall the packages using the same feed and nuget client. The visual studio package manager should install the packages to the correct location. So you can either ensure that you have the correct versions, or just hope it will be ok and continue with the following:
Delete all of the packages from the packages folder (hopefully all your projects use the same folder otherwise this may be laborious).
Clear your nuget package cache from visual studio (there's a button to do this under Tools -> Options -> Nuget Package Manager)
In visual studio, open the nuget package manager console.
Run 'Update-Package -reinstall'
It may take some time depending on how many packages and projects you have, but this will hopefully ensure your project reference hint paths will match the packages' installed locations.
We migrate our project to NET STANDARD, but when the project is compiled many errors appear on the errors list:
Severity Code Description Project File Line Suppression State
Error Build action 'EmbeddedResource' is not supported by one or more of the project's targets. MyApp C:\desenvolvimento\aplicativo\App\MyApp\App.xaml 0
the project runs normally but many of this errors appears...
i am using the latest version of Visual Studio 2015 and Xamarin, all the libs and softwares are up to date.
These are only Intellisense errors. If you just switch your error list filter to Build Only (instead of Build + Intellisense), then you will see that they disappear and your project will continue to build.
If your project is building correctly but these errors persist, this is because Visual Studio keeps a cache of the errors on .suo (Solution User Options) and sometimes these errors are not refreshed as should.
To force refresh close Visual Studio and delete all .suo files (including inside .vs folder). You will loose all state for this project (open files and windows, windows positions etc).
I had this issue and searched online, eventually found this answer https://forums.xamarin.com/discussion/comment/89268/#Comment_89268
It looks like a tag in the older VS solution file is the cause.
As stated in the answer, you can fix the build error by opening up the .csproj file in a text editor, finding the EnsureNuGetPackageBuildImports Target and removing it.
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Xamarin.Forms.1.2.2.6243\build\portable-win+net45+wp80+MonoAndroid10+MonoTouch10\Xamarin.Forms.targets')" Text="$([System.String]::Format('$(ErrorText)','..\packages\Xamarin.Forms.1.2.2.6243\build\portable-win+net45+wp80+MonoAndroid10+MonoTouch10\Xamarin.Forms.targets'))" />
</Target>
Loaded solution and all working.
Update:
So, I logged on to the server and opened the project with VS 2013. I clicked "enable nuget package restore" on the solution context menu. Now, it builds on the server. The problem is, I don't know how to do the same thing in VS 2015. There is no right-click menu. I have already enabled "allow automatic package restore" in Options.
-End update
I have a project in Visual Studio 2015. I can build and run it successfully on my local machine. It uses Newtonsoft.Json (JSON.net) which it obtains from Nuget. When I check in, and my continuous integration build runs on the build server, it throws an exception that it cannot locate the JSON.net assemblies:
The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?)
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets (1605): Could not resolve this reference. Could not locate the assembly "Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, 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 have looked all over to see what is causing the Nuget package to fail. Is it because I am using Visual Studio 2015? Is Nuget jacked up?
Has anyone experienced this issue?
Check the references in your project carefully against the entry in your packages.config file.
I had this same error and found that the project referenced Newtonsoft.Json 4.5.1 in its references, but in packages.config, the entry was as follows:
<package id="Newtonsoft.Json" version="5.0.8" targetFramework="net45" />
Changing the entry in packages.config to 4.5.1 instead of 5.0.8 fixed the problem.
<package id="Newtonsoft.Json" version="4.5.1" targetFramework="net45" />
I discovered this by examining the local _work folder on my CI build server, and finding that the location that it was trying to pull the .dll from was not available in there; then I traced it back to figure out why. (Another possible cause of this issue is a NuGet package that has been deprecated. I had one of those as well that threw the same error.) I'm not sure how they got out of sync; this was a project that was originally worked on by someone else that I inherited.
Hopefully, even if this doesn't solve the problem for you, this will help somebody else down the road.
Immediately after we upgraded to visual studio 2010 and the 4.0 framework our trunk build started breaking with the Could not load file or assembly error.
We determined that a 3.5 project couldn't reference a 4.0 project else we'd get this error because, as the error states, This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.
We've since resolved this and the trunk has been building fine.
I recently did a branch and tag, however, and suddenly this error has resurfaced when I try to build the branch; except the error is regarding one of our own .net 4.0 project's reference to System.Configuration DLL.
Towps.Namespace.MyService.csproj in Core.Dev\Towps\Projetcs\Application\MyService:
RG0000: Could not load referenced assembly
"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll". Caught a BadImageFormatException saying "Could not load file or assembly 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.". in ResGen(0, 0)
I tried setting the specific version property on that system.Configuration DLL ref to true. I can see in it's properties that the runtime version is v4.0.30319 and the Version is 4.0.0.0. The path to the DLL ref is C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\System.Configuration.dll which to me looks fine.
The target framework for the csproj file that CrusieControl is using MSBuild to try to build is targeting framework 4.0. Again seems fine.
It builds in the IDE for both trunk & branch. Cruise Control build it in the trunk. The branch build fails when CrusieControl tries to build.
Any ideas what could be happening?
It could be an MSBuild mismatch but I've scanned the config files and msbuild proj files that CruiseControl is using and there are no references to older MSBuilds; which makes sense since all those were updated to get the trunk working.
The branch was simply a copy of the trunk so I'm having difficulty determining what could be the difference!
It turns out that after I branched, all the .proj files in my branch build directory that cc.net uses were back to using ToolVerison="3.5".
I thought I committed all the ToolsVersion="4.0" proj and config changes to the trunk from which I made the branch; evidentially not.
The difference could easily be hint paths no longer lining up on the new branch. However there's not a log to go on in your description. What are the command line options you are passing? In ccnet.config and also any others that may get in if ccnet.config is pointing at a build script that calls msbuild instead of directly to a .sln or .csproj file.
Turn on /v:d for the msbuild on BOTH and then compare the reference resolutions (or build order, etc..) for that assembly or other ones involved/near it.
Also are you providing the path to msbuild on both?
msbuild4="C:\WINNT\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe"
<msbuild>
<executable>$(msbuild4)</executable>
in your ccnet.config?
I've seen it report the 2.0 build executable during a msbuild4 /tv:3.5:
<Message Text="MSBuildToolsPath:$(MSBuildToolsPath)" />
<Message Text="MSBuildToolsVersion:$(MSBuildToolsVersion)" />
MSBuildToolsPath:C:\WINNT\Microsoft.NET\Framework\v2.0.50727
MSBuildToolsVersion:2.0
so that didn't seem very useful.
I'd like to see the config blocks for both branch and trunk.
I know I had some paths in the buildscript that failed in my branch because there was a hardcoded path that would not be valid for the branch. I had to adjust the ccnet.config to pass in arguments for those items to override for the branch.
Please check .net framework version supported by your client. For example sharepoint2010 will not support dll built by 4.0 or higher .net framework. It will support only 3.5 or below.
A bit late I know, but if anybody else has this issue, try adding the RuntimeVersion into your .dna file if it does not already exist.
<DnaLibrary Name="PROJECTNAME" RuntimeVersion="v4.0">