I have a .NET Standard class library project with a number of POCO's. This project is built using TeamCity and published as a Nuget package using the built-in Nuget server.
The problem I'm having is when it's installed into my solution with a number of .NET Framework class library projects and ASP.NET MVC and Web API projects (set to .NET Framework 4.7.1), it seems to be stuck on an older version and is not recognising any new classes or methods I add to the project - e.g. NewMethod1()
Project File for Nuget package
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net461;net462;net47</TargetFrameworks>
<Version>1.0.0</Version>
</PropertyGroup>
<PropertyGroup>
<NetStandardImplicitPackageVersion>2.0.0</NetStandardImplicitPackageVersion>
<Description>Standard entities used within our systems</Description>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<FileVersion>1.0.0.0</FileVersion>
<Authors>Company X</Authors>
<Company>Company X</Company>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<OutputPath>bin\Release</OutputPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<OutputPath>bin\Debug</OutputPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
</ItemGroup>
</Project>
TeamCity is using the 'dotnet' restore, build & pack options.
The package is stored in my Nuget cache located in C:\Users\antho.nuget\packages. When I use Object Browser to inspect the dll, it contains the new classes and methods (e.g. NewMethod1()).
When I install this package into my .NET Framework solution, no errors occur during the installation. If I try and use the new method - NewMethod1() - the code doesn't compile.
If I create a brand new solution and ASP.NET MVC project and install the package, the new method can be used in code and it compiles successfully.
What could be causing the new version not to be installed correctly? It's tricky to provide a sample reproducing the issue because it seems to work in a new project.
Update
If I add a new project to the solution and install the Nuget package, it gets the latest version.
Project A
<PackageReference Include="AutoGuru.Shared.Utilities" Version="1.0.369" />
public class Class1
{
public void Test()
{
"dfdfdfdf".SanitizeVehicleRego();
}
}
Project B
<PackageReference Include="AutoGuru.Shared.Utilities">
<Version>1.0.369</Version>
</PackageReference>
public class Class1
{
public void Test()
{
"fdfdf".SanitizeVehicleRego();
}
}
Project B compiles successfully and Project A doesn't. SanitizeVehicleRego() is a string extension method in the AutoGuru.Shared.Utilities package.
My answer it quite big, so I add an answer instead of comment.
Step 1
Check the output when you restore the package, sometimes dotnet restore resolve an other version automatically ( you should have a warning for this kind of things in your console ).
Step 2
If any information was found in Step 1. Try to clean all your local nuget cache.
dotnet nuget locals all --clear
I'm not sure if local nuget packages are under cache stategy. But if they are, it should resolve the correct version of your package.
Related
I am trying to add a nuget package "Azure.ResourceManager" to an existing project.
Here is the .csproj file:-
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.6.0" />
<PackageReference Include="Azure.ResourceManager" Version="1.0.0" />
<PackageReference Include="Azure.ResourceManager.Resources" Version="1.0.0" />
....
</ItemGroup>
</Project>
I ran the nuget restore command on the solution, and I have checked that the package is installed through the Visual Studio Package Manager Console, using command
PM> Find-Package ResourceManager
Id Versions Descriptio
n
-- -------- ----------
Azure.ResourceManager {1.0.0} Azure m...
Azure.ResourceManager.Communication {1.0.0} Azure m...
Azure.ResourceManager.Deployment... {1.0.111} This pr...
Azure.ResourceManager.Deployment... {1.0.111} This pa...
However, when I try to import this package into a class, the type cannot be resolved.
I wondered if the package and project targeted different versions, so I checked.
Target frameworks supported by package
Target framework supported by project
In summary,
As far as I can tell, both project and package support .Net Core 3.1 as a target framework.
Package is installed into project, but cannot be imported into class
Another thing I noticed is that the type "ResourceManager" is being searched for in the "Microsoft.Azure" namespace instead of "Azure"
Looking for any pointers to resolve the issue.
I learnt that the issue was happening because of naming conflicts within the namespace that I was trying to add the import in. There seems to have been another namespace "Azure." within the one I was adding code to. Adding a glocal prefix helped resolve the issue.
using global::Azure.ResourceManager;
This seems like a bug. I just created a solution with a .NET core 3.1 project inside. I used the Nuget Manager ui and it worked fine. Have you tried installing it that way?
Visual Studio 2019
C#
Project 1:
Dependencies: Meta.Numerics 4.1.4. I added Meta Numerics via the Manage NuGet Packages for Solution
Project 1 is a Class Library
Will be compiled and .dll will be shared with an associate who will use it in the main application
Project 1 builds just fine using Debug.
using System;
using Meta.Numerics;
namespace LeakDetection
{
public class LeakDetectionOperations
{
public LeakDetectionOperations(int co = 24)
{ }
public int leakCheck()
{
double result = ComplexMath.Abs(10);
return 0;
}
}
}
Project 2
Dependencies: Project 1. Imported via Add references, browser, and selected the .dll from project 1
Project 2 is just a simple test project that I'm using to test the .dll object.
It runs, but throws an exception when it attempts to call the ABS function of Meta.Numerics.
using System;
using LeakDetection;
namespace LeakTest
{
class Program
{
static void Main(string[] args)
{
LeakDetectionOperations obj = new LeakDetectionOperations();
int ret;
ret = obj.leakCheck();
Console.WriteLine("Hello World!");
}
}
}
I've followed the instructions from the Meta.Numeric gitrepo regarding installation. The installation was done as they suggested to install the package. I've also cleaned build, and rebuilt fresh. I also changed from debug to release to see if there was anything related to the debug that was causing the error. As you can see at the above code, its fairly minimum, as this is not my actual code. Its a bit more elaborate, but rather than posting the full code, this is the minimum usable code that replicates the issue I'm having. Nothing from the Meta.numeric library is usable.
I usually work in Python, have some experience in C and C++, but I have used make files to compile in linux. Using C#, visual studio is fresh for me.
Any suggestions as to where I should look would be much appreciated.
UPDATE:
Per the suggestion by #kit, I've included the .csproj file for project 1 below
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>Leak_Detection</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Meta.Numerics" Version="4.1.4" />
</ItemGroup>
</Project>
.csproj for project 2
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Reference Include="Leak Detection">
<HintPath>..\..\Leak Detection\Leak Detection\bin\Debug\netcoreapp3.1\Leak Detection.dll</HintPath>
</Reference>
</ItemGroup>
</Project>
I was able to kind of replicate your issue (not exactly but I got the same kind of error). I believe your test project is in .NET framework. If I do not reference any nuget package in test project, failure occurs. But, if I install any nuget package and later on uninstall it, program runs successfully. For testing, I installed and uninstalled Newtonsoft.Json package. So, there is a bug in initialization of nuget package engine for .NET framework where in absence of any nuget packages, it is not able to resolve transitive nuget dependencies. If I create test project in .NET core, test project runs without any issue.
I have also put code in github
https://github.com/dheerajjain11/MissingDLLIssue/
MetaNumerics is .NET Standard library
MetaNumericsTest is .NET Framework Test project where I installed and uninstalled nuget package. Now, it runs successfully
MetaNumerics2 is .NET Framework Test project which fails
MetaCore is dotnet core project which runs without any issue and no workarounds
I don't know if this is normal or not, but what resolved the issue for me was installing the package via the Nuget package manager on both the Library and the Console application. Both builds need a reference.
What I was doing previously, was only installing the package for the library build. Seeing how the console application was then compiling with the .dll being referenced and called, the calling application also needed the package installed.
I have a purchased license of the DLLs (6.9.4.10) and my *.csproj contains this:
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.1.0"/>
...
<PackageReference Include="System.IO.Packaging" Version="4.5.0"/>
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.5.0"/>
<PackageReference Include="ZKWeb.System.Drawing" Version="4.0.0"/>
</ItemGroup>
...
<ItemGroup>
<Reference Include="SautinSoft.PdfFocus">
<HintPath>..\PDF Focus .Net Full (6.9.4.10)\DLLs\Net Core 2.0\SautinSoft.PdfFocus.dll</HintPath>
</Reference>
</ItemGroup>
I am trying to convert a PDF into a DOCX-file (which worked in .NET 4.5).
This is the relevant part of the code:
....
SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();
f.Serial = Settings.GetAppSetting("PdfFocusSerial", "**MySerial**");
f.OpenPdf(buffer);
if (f.PageCount > 0)
{
f.WordOptions.Format = SautinSoft.PdfFocus.CWordOptions.eWordDocument.Docx;
var result = f.ToWord(); //f.Exception set after this
...
}
...
I've checked that the same buffer is sent in as in the old code, but the output differs by some bytes. And I get an Exception set in f.Exception, which is:
{System.Collections.Generic.KeyNotFoundException:
The given key '0' was not present in the dictionary. ...
When I try to open the newly created *.docx-file, Word says it's damaged. After clicking through some dialogs it can still open the file.
Anyone have any ideas?
Is this a known bug for this library in .Net Core 2.1? (Only 2.0 is mentioned on their website)
I've also tried the free version published on NuGet with the same results.
EDIT
This was indeed a bug in the .NET Core specific version. They have fixed this in version 6.9.6.29.
My Name is Dmitry and I work in SautinSoft.
Thank you for your issue. You are right. We have some problems with PDF Focus.Net and Net Core 2.1
Our developers try to fix this issue. We have found where is a bug (resources/fonts) and I hope, that we will prepare a new version very quickly.
I'll inform you.
If you want to use "RTF to HTML" for Net Core 2.X-6.X please add these references in your project:
System.Drawing.Common, 4.7.0 or up.
System.IO.Packaging, 4.4.0 or up.
System.Text.Encoding.CodePages, 4.5.0 or up.
System.Xml.XPath.XmlDocument, 4.3.0 or up.
But If it will be Net Core 7.X for LinuxOS - it doesn't work, because the System.Drawing.Common NuGet package is now attributed as a Windows-specific library. The platform analyzer emits warning at compile time when compiling for non-Windows operating systems.
So I've got a dotnet core app, I'd like to use Twilio so I performed the following from the command line.
dotnet add package Twilio
All went well, no errors. It adds version 5.1.1 of Twilio packages. But building the app now gives me
The type or namespace name 'Twilio' could not be found
I'm running .Net core version 1.1 with the equivalent 1.0.1 SDK.
Any ideas?
Did you restore? The following works for me.
dotnet new console
dotnet add package Twilio
dotnet restore <---- We need to restore after adding a package.
dotnet build
Program.cs
using Twilio;
class Program
{
static void Main(string[] args)
{
TwilioClient.SetUsername("foo");
}
}
DotNetCoreTwilio.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Twilio" Version="5.1.1" />
</ItemGroup>
</Project>
Ive just had this problem with a core 2.2 project. It turns out i needed an additional using statement of:
using Twilio.Types;
Visual studio wasnt providing any suggestions when it was referenced as follows:
twilio.Types.PhoneNumber("xx");
Changing the reference to the below prompted a new using suggestion from Visual Studio:
PhoneNumber("xx");
Hope this helps someone
I was playing around with VS2015 and ASP.NET vNext, and got stuck on trying to add a reference from vNext class library (kproj) to a regular class library (csproj) in the same solution. Visual Studio 2015 shows the following error message:
"The following projects are not supported as references".
Is it possible at all to add references to csproj from vNext class libraries?
Note: The kpm command has been replaced by dnu.
Visual Studio 2015 Preview (as of writing this) comes with the ASP.NET 5 stable release beta1. In this version there is no way to reference a csproj project from an ASP.NET 5 project.
However, on the development feed of ASP.NET 5 the command kpm wrap was introduced to support referencing csproj-projects from ASP.NET 5 projects. See the github issue #827 in the aspnet/KRuntime repository and pull request #875 which closes the issue.
Here is an example how you would use kpm wrap:
Make sure the newest version of the KRuntime is installed (check this with the kvm list command) (I tested this with version 1.0.0-beta2-10709).
Create an ASP.NET 5 class library project, I used the name ClassLibrary1.
Create a "normal" csproj class library, I named this ClassLibrary2 (make sure you put this in the src folder).
From the commandline, from the solutiondirectory run the command
kpm wrap .\src\ClassLibrary2
This gives the output:
Wrapping project 'ClassLibrary2' for '.NETFramework,Version=v4.5'
Source C:\Users\andersns\Source\ClassLibrary1\src\ClassLibrary2\ClassLibrary2.csproj
Target C:\Users\andersns\Source\ClassLibrary1\wrap\ClassLibrary2\project.json
Adding bin paths for '.NETFramework,Version=v4.5'
Assembly: ../../src/ClassLibrary2/obj/debug/ClassLibrary2.dll
Pdb: ../../src/ClassLibrary2/obj/debug/ClassLibrary2.pdb
Now in the project.json of ClassLibrary1 (which is ASP.NET 5) you can add a reference to ClassLibrary2 with this:
...
"dependencies": {
"ClassLibrary2": ""
},
...
Note: kpm wrap did not run properly for me with cmd, I needed to launch powershell to make it run.
Starting with (Visual Studio 2015 RC) the kpm command has been replaced by dnu
The dnu command stands for (.NET Development Utility)
dnu wrap .\src\ClassLibrary2\ClassLibrary2.csproj
New ASP.NET Features and Fixes in Visual Studio 2015 RC
http://blogs.msdn.com/b/webdev/archive/2015/04/29/new-asp-net-features-and-fixes-in-visual-studio-2015-rc.aspx
I have found it easiest to simply create a corresponding .kproj for the .csproj I want to reference. The .kproj does not require listing every included file, so this is rather straightforward.
You can create YourProject.kproj as a text file with the contents below, and only replace the [REPLACE_WITH_UNIQUE_GUID] and [ROOT_NAMESPACE].
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\AspNet\Microsoft.Web.AspNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>[REPLACE_WITH_UNIQUE_GUID]</ProjectGuid>
<RootNamespace>[ROOT_NAMESPACE]</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<ProduceOutputsOnBuild>True</ProduceOutputsOnBuild>
</PropertyGroup>
<Import Project="$(VSToolsPath)\AspNet\Microsoft.Web.AspNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
You can then add this project to your solution and reference it from your MVC 6 project.
In addition to this answer I found out that you need to use the if directive (#if) to make the call without errors:
Something like:
#if ASPNET50
using class2
#endif
When you use it in a call you need to do the same.
#if ASPNET50
ViewBag.Message = class2.Class1.Greetings()
#endif