Visual Studio 2017 package tab is missing in project settings - c#

I created a simple library .NET Framework project.
I would like to generate NuGet packages after build as described here.
However, the Package tab is missing, here is a screenshot:

Visual Studio 2017 package tab is missing in project settings
That because your project is library .NET Framework, which still using packages.config to manage NuGet packages. And Package tab is only supported by the new nuget package management form: PackageReference.
.NET Standard class library or .NET Core projects come with PackageReference enabled by default. So you can create .NET Standard class library or .NET Core project, then you will see Package tab on the properties window.
If you want to use the Package tab for library .NET Framework project, you can convert your project from the old .csproj to new .csproj, (Right click your project->Unload project->Edit .csproj. Replace the contents of your csproj with the following:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net46</TargetFramework>
</PropertyGroup>
</Project>
See Old csproj to new csproj: Visual Studio 2017 upgrade guide for more info about convert old .csproj to new .csproj.
Note: Need to delete the AssemblyInfo.cs file in the Properties.
After convert to new .csproj, you will get the Package tab for library .NET Framework project:
Hope this helps.

Related

Visual Studio 2022 Mac Error: NuGet packages need to be restored before building. NuGet MSBuild targets are missing and are needed for building

I have a .Net 6 project, I am getting the below error.
Error: NuGet packages need to be restored before building. NuGet
MSBuild targets are missing and are needed for building. The NuGet
MSBuild targets are generated when the NuGet packages are restored.
csproj file:
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Exe</OutputType>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerfileContext>..\..</DockerfileContext>
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>
Visual studio version: 17.4.2
I have followed this question also (restoring the packages), But it didn't help.
But I am able to build from the terminal using dotnet build successfully.
Also, I have other projects targeting .net 6 and I can build successfully using visual studio.

Package X is not compatible with netcoreapp3.1

I'm trying to run my .net core 3.1 project in VS 2019 but I'm getting errors like a below during building.
Severity Code Description Project File Line Suppression State
Error NU1202 Package System.Diagnostics.DiagnosticSource 4.5.0 is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1). Package System.Diagnostics.DiagnosticSource 4.5.0 does not support any target frameworks. WebApi.Base C:\Users\ilyas.varol.TEST\source\repos\performancemanagementprojects\WebApi.Base\WebApi.Base.csproj
Notes:
I made reinstalling all packages and .net core 3.1 sdk
The same project is running in another computer
UPDATE
I still haven't solve my problem. Therefore I want to elaborate my question with screenshots. I hope someone can help me.
Error list
Nuget Package Manager > Consolidate
First, clean nuget caches or delete all files under C:\Users\xxx(current user)\.nuget\packages.
Then, delete bin and obj folder.
Rebuild the project to test again.
I clicked right click on sln and then I clicked "Clean Solution" and Rebuild Solution". Finally, My problem is solved.
Following worked for me on VS 2019,
Tools-->Nuget Package Manager-->Package Manager Settings-->General-->Clear All NuGet Cache(s)
I had the same problem, as mentioned in the docs I updated the target framework.
Specifically, of my class libraries (in Blazor server core 3.1).
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework> //remove this
<TargetFramework>net6.0</TargetFramework> //add this
</PropertyGroup>
</Project>
After this, you need to remove the bin, obj folder and rebuild the project.
This should get you are up and running again.
For me 5.0.10 worked properly. Today the latest version of this NuGet package is 6.0.6 but I tried 5.0.10 and worked properly

Enable all rules with .NET analyzers in .NET standard projects

I am moving my project to the new .NET Analyzers using Rosyln, previously I was using the nuget package.
I'm trying to do the process described here:
Migrate from FxCop analyzers to .NET analyzers
Now my csproj looks like:
<Project>
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
</PropertyGroup>
</Project>
If TargetFramework is net5.0, all rules are return an error, but I cannot make it work when it's set to netstandard2.0.
I cannot move to net5.0 because this dll is referenced by a .NET 4.8 project.
If you add <AnalysisLevel>5</AnalysisLevel> to your project file, you can instruct projects which do not target .NET 5.0 to use the same default rules as a project targeting net5.0 would do by default.
You can find more information about this here.
Since moving to .Net 5 is not an option (where the analyzer is enabled automatically), I would suggest using the nuget packageMicrosoft.CodeAnalysis.CSharp that perform the analysis.

Select framework version for .NET Core Class Library project - Visual Studio 2019

In Visual Studio 2019 if I try to create an ASP.NET Core web application project, I get to select the framework version in the following screen -
But when I try to create a .NET Core class library project I am prompted with the following screen which does not provide any option for selecting the framework version -
Clicking the Create button always creates the project right away taking the latest .NET Core version installed on my machine.
So, how can I select the framework version while creating the class library project? Or do I have to change it manually every time after creation ?
The ASP.NET project creation dialog providing a framework selection seems to be an exception in .NET Core / Standard projects to me. At least since VS2019 with the new "New Project" dialog, you have the following options after creating the project with this dialog.
"Normally" (to my experience), you right-click the project file in the Solution Explorer, choose "Edit Project File" and modify the <TargetFramework> element by naming one of the valid target framework monikers. See MSDN about them.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
</Project>
You can also rename the element to TargetFrameworks (note the pluralized name) to build against multiple frameworks at the same time, which are ; separated:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net451;netstandard2.0;netcoreapp3.0</TargetFrameworks>
</PropertyGroup>
</Project>
Alternatively, you can also choose "Properties" from the project right-click menu and select a framework via a slightly dated UI not supporting all of the new csproj features, like said multi targeting:
If you need many new projects building against a specific framework, create a template csproj and just copy and rename it.
Also, if you want to build against preview versions of .NET Core in non-preview versions of VS, ensure you allow usage of them in Tools > Options > Environment > Preview Features.

Visual Studio 2008 Project in 2013 Solution

I have a Visual Studio 2008 project that is a Smart Device project targeting a .NET 3.5 Compact Framework Windows CE device and it currently references a 3.5 class library project.
What I would like to do is be able to add the class library into a Visual Studio 2012/2013 solution without "migrating" it.
For example the structure is currently:
VS2008 Solution
Smart Device Project
Class Library Project
I want to have is:
A VS2008 Solution
Smart Device Project
Class Library Project
A VS2013 Solution
Class Library Project
ASP.NET MVC Project
The result of this would be that I can work on the Smart device project in VS2008 and add classes to the Class Library Project, and then be able to open the VS2013 solution file and have those new classes available.
When I look at the difference between a 2008 Class Project and a 2013 Class Project csproj files, the only thing that really is different is the ToolsVersion on the Project element (http://msdn.microsoft.com/en-us/library/bcxfsh87.aspx).
In VS2008 the ToolsVersion is 3.5, but in VS2013 its 12.0.
I've attempted to make the ClassLibraryProject switch between 3.5 and 12.0 for the ToolsVersion with the following:
<Project ToolsVersion="$(ProjectToolsVersion)">
<Choose>
<When Condition="'$(VisualStudioVersion)' != ''">
<PropertyGroup>
<ProjectToolsVersion>12.0</ProjectToolsVersion>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup>
<ProjectToolsVersion>3.5</ProjectToolsVersion>
</PropertyGroup>
</Otherwise>
</Choose>
<!-- other project stuff -->
</Project>
I can open this fine in VS2013, but when I open it in VS2008 it says:
Unable to read the project file 'ClassLibraryProject.csproj'.
C:\Test\ClassLibraryPorject.csproj: The tools version "$(ProjectToolsVersion)" is unrecognized.
Please Note: I am not able to migrate the entire project to VS2013 because VS2013 does not support Smart Device projects.
VS2008 which uses MSBuild 3.5 should be able to handle ToolsVersion 12, as in that case it automatically falls back to ToolsVersion 3.5.
Thus, you should migrate the class library project in VS2013, and it should be able to work still in the VS2008 solution without any modification.
VS2008 and MSBuild 3.5 gives you the error, because Choose is evaluated later than Project, so what you define in Choose (aka ProjectToolsVersion) cannot be used in Project.

Categories

Resources