Whenever I create a new web project using my visual studio 2017, it creates it with a file named packages.config which contains reference for:
Microsoft.CodeDom.Providers.DotNetCompilerPlatform
<package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="2.0.0" targetFramework="net461" />
At my work we are not allowed to use any nuget packages.
So everytime I have to manually go and uninstall Microsoft.CodeDom.Providers.DotNetCompilerPlatform, which will remove the packages.config file and updates my web.config file.
Is there a way I can prevent visual studio 2017 from doing this when I create a project itself?
Thank you!
Related
I have some nuget package hosted in my gitlab project. And I need debug this package and can't do this on Visual Studio for Mac.
Here is my csproj file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;netcoreapp3.1</TargetFrameworks>
<!-- Optional: Publish the repository URL in the built .nupkg (in the NuSpec <Repository> element) -->
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<!-- Optional: Embed source files that are not tracked by the source control manager in the PDB -->
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<!-- Optional: Build symbol package (.snupkg) to distribute the PDB containing Source Link -->
<IncludeSymbols>true</IncludeSymbols>
<!-- Recommended: Embed symbols containing Source Link in the main file (exe/dll) -->
<DebugType>embedded</DebugType>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<EmbedAllSources>true</EmbedAllSources>
<PackageVersion>1.0.18.0</PackageVersion>
<AssemblyVersion>1.0.18.0</AssemblyVersion>
<FileVersion>1.0.18.0</FileVersion>
<InformationalVersion>1.0.18.0</InformationalVersion>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
</PropertyGroup>
<ItemGroup Condition="$(TargetFramework.StartsWith('netstandard2.0')) Or $(TargetFramework.StartsWith('netstandard2.1'))">
<PackageReference Include="nlog" Version="4.6.2" />
<PackageReference Include="System.Threading" Version="4.3.0" />
<PackageReference Include="Microsoft.SourceLink.GitLab" Version="1.0.0" PrivateAssets="All"/>
<Compile Include="ISynchronizationContext.cs" />
<Compile Include="TaskExtensions.cs" />
<Compile Include="AsyncAwaiter.cs" />
</ItemGroup>
<ItemGroup Condition="$(TargetFramework.StartsWith('netcoreapp3.1'))">
<PackageReference Include="Microsoft.SourceLink.GitLab" Version="1.0.0" PrivateAssets="All"/>
<PackageReference Include="nlog" Version="4.6.2" />
<PackageReference Include="System.Threading" Version="4.3.0" />
<Compile Include="*.cs" />
</ItemGroup>
<PropertyGroup>
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
</PropertyGroup>
</Project>
this is my deploy part of .gitlab-ci.yml:
deploy:
stage: deploy
script:
- dotnet pack -c Release
- dotnet nuget add source "$CI_API_V4_URL/projects/$CI_PROJECT_ID/packages/nuget/index.json" --name $CI_PROJECT_TITLE --username $CI_REGISTRY_USER --password $CI_REGISTRY_PASSWORD --store-password-in-clear-text
- dotnet nuget push "Source/bin/Release/*.nupkg" --source $CI_PROJECT_TITLE
Debug nuget package working in Visual Studio 2019, but not working in Visual Studio for Mac.
In this article I have read that:
In Visual Studio for Mac, support for symbol servers doesn’t exist yet, so Source Link only works with NuGet packages that contain their own debug symbols.
What I need to do to enable debugging my nuget package in Visual Studio for Mac?
You can try use Debugging NuGet packages with Source Link,According to xamarin documents:
Source Link technology enables source code debugging of .NET
assemblies from NuGet that ship .PDBs with links to source files.
Source Link executes when developers create their NuGet package and
embed source control metadata inside assemblies and the package. When
Source Link is enabled in Visual Studio for Mac, the IDE will detect
if source files are available for installed packages. Visual Studio
for Mac will then offer to download them, which will allow you to step
through the package code. Source Link also works with Mono Base Class
Library code for Xamarin projects, allowing you to step into .NET
Framework code as well. Source Link provides source control metadata
to create a great debugging experience.
Here is how you do it, you could check this document https://learn.microsoft.com/en-us/visualstudio/mac/source-link?view=vsmac-2019
According to this comment by TysonMN, the following in your .csproj file will embed both PDB symbols and associated source code into .nuget, such that VS can find them:
<PropertyGroup>
<DebugSymbols>True</DebugSymbols>
<DebugType>Embedded</DebugType>
<EmbedAllSources>True</EmbedAllSources>
</PropertyGroup>
Not tested on Mac - say in comment whether it works or not.
I have three projects I'm building
FooBar.Abstractions
FooBar.AspNetCore
FooBar.AspNetCore.IntegrationTesting
The FooBar.AspNetCore and the FooBar.AspNetCore.IntegrationTesting projects both have references to FooBar.Abstractions. I want to package and ship all three of these as individual NuGet packages.
I started with a NuGet.config file that looks like this locally:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="aspnetcore_abstractions" value="./src/FooBar.Abstractions/bin/Debug/" />
</packageSources>
</configuration>
Then I add the package to my projects
<ItemGroup>
<PackageReference Include="FooBar.Abstractions" Version="2.0.0-preview1" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
</ItemGroup>
This really sucks though as each time I make a change in the FooBar.Abstractions project I have to go into my C:\.nuget\packages folder and delete the cache before my FooBar.AspNetCore project can restore the newly compiled version from my solution.
If I just add FooBar.Abstractions as a project reference, and then I ship the two packages to NuGet.org, how does that affect users that install the two packages across different projects in their solutions. Does NuGet and .Net figure it all out, knowing that they're the same referenced assembly? I assume in this case the FooBar.AspNetCore project will ship with the FooBar.Abstractions.dll in it if I add it as a project reference.
I don't know if that causes conflicts knowing that the package ships that .dll, then a customer installs the Abstractions package explicitly that contains the same .dll.
How do you handle this with NuGet packaging with the newest versions of NuGet? How do I constrain FooBar.AspNetCore to use the same FooBar.Abstractions.dll version between the package reference and the NuGet package others will install? I can't force PackageReference Include="FooBar.Abstractions" Version="2.2" if I'm adding it as a project reference instead can I?
When you pack a project with at project reference, NuGet converts the project reference into a NuGet dependency. It figures out the dependency version based on what version that project would be if it were packed. There is no need to use PackageReference when packing. As you discovered/explained, doing so makes local development much more difficult.
Therefore the solution to your problem is to just use ProjectReference when the projects are in the same source code repository.
I have a Dotnet Core 2.1 project which has both a nuspec and a csproj file - one major hassle is that the csproj describes dependencies like this:
<ItemGroup>
<PackageReference Include="Refit" Version="4.6.16" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.1" />
<PackageReference Include="Refit.HttpClientFactory" Version="4.6.16" />
</ItemGroup>
While the nuspec does this:
<dependencies>
<dependency id="Refit" version="4.6.16" />
<dependency id="Refit.HttpClientFactory" version="4.6.16" />
<dependency id="Microsoft.AspNetCore.All" version="2.1" />
</dependencies>
Both are easily out of sync and keeping the same information twice is annoying.
Is there a way to avoid that?
There is certain to be a easy way for this, just use dotnet pack instead of nuget pack and .csproj files instead of .nuspec files.
dotnet pack supports 2 ways to specify the nuget package properties.
The legacy way: using .nuspec file, which would disable the 2nd way
The new way: specifying them in .csproj file
dotnet pack supports both ways but you must add a NuspecFile property to reference the .nuspec file and there are a lot of bugs and feature missings for the legacy way, which means you can only use the new one.
dotnet pack executes restore and build on the project and packs it with a automatically generated .nuspec file resolving all nuget metadata properties in .csproj as .nuspec properties and all projects references as nuget package references (This is not available with manually specified .nuspec file), so that versioning, dependency, and package file structure things can be automatically ensured.
My own library could be an example. Version and dependency things are specified for only once at where they are supposed to be and there are no longer any annoying duplicate configurations. Executing dotnet pack on the solution directory would generate all good .nupkgs on the dist directory.
I am facing a problem to install packages of Serilog.Sinks in an old project, e.g. when I try installing Serilog.Sinks.MSSqlServer I get the following error:
An error occurred while retrieving package metadata for Serilog.2.6.0
I have already installed package Serilog.2.6.0 and the process went fine, I tried running the code that uses this library and it works okay, but in case I try to uninstall this package I get the error:
Object reference not set to an instance of an object
Thus, I think that something might be wrong with Serilog.2.6.0 in my machine, since I cannot uninstall it or install any of its sinks, but I can't figure out the problem.
Details:
Visual Studio 2015
.NET Framework 4.5 Web Forms
Hi this worked for me nugget install Serilog.Sinks
If you can't uninstall your nuget via package manager console or with Nuget Package Manager, you still have the option to uninstall it. Open your package.config file.
Looks like this:
<packages>
<package id="Respond" version="1.2.0" targetFramework="net461" />
<package id="Serilog" version="2.6.0" targetFramework="net461" />
<package id="WebGrease" version="1.5.2" targetFramework="net461" />
</packages>
There you will find the id of Serilog your dependency with the version associated. Remove that line. And then unload your project, edit it, there you will find the HintPath of Serilog:
Looks like this:
<Reference Include="Serilog, Version=2.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
<HintPath>..\packages\Serilog.2.6.0\lib\net46\Serilog.dll</HintPath>
<Private>True</Private>
</Reference>
Then the package Serilog could be uninstalled complete by manually.
Besides, if you re-install that package still get the same error after uninstall it, this issue should be more related to the NuGet rather than the package Serilog.
In this case, please try to uninstall the NuGet Package Manager for Visual Studio 2015 from Tools->Extensions and Updates, restart Visual Studio. Then install the latest version NuGet:
https://dist.nuget.org/visualstudio-2015-vsix/latest/NuGet.Tools.vsix
After the installation is completed, Reopen the Visual Studio in Administrator mode (right-clicked Visual Studio and started in Administrator mode), try to install that package again, check if it works fine.
The thing that worked for this case, from those I tried, is copying the references (.dll files) from another project where they're working fine. Thank you for your answers! :)
It works fine with me with the following package.config setting:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Serilog" version="2.6.0" targetFramework="net461" />
<package id="Serilog.Exceptions" version="4.1.0" targetFramework="net461" />
<package id="Serilog.Sinks.File" version="3.2.0" targetFramework="net461" />
</packages>
I have a .Net Core project web project, and for various reasons want to convert it to a .Net Framework project.
Is there an easy way to do this, or do I have to start again and import the code from the previous projects
I have loaded core project to the VS 2017 RC Community and open *.csproj in text editor.
Just delete teg
<RuntimeFrameworkVersion>
and replace
<TargetFramework>netcoreapp1.1</TargetFramework>
to
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
And after all in project properties set to any another framework and reset back (VS reload and repair *.csproj file).
This worked for me in VS2017:
Start with .net core web project template.
Edit *.csproj so it looks like this:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="2.1.3" />
<PackageReference Include="Microsoft.AspNetCore.CookiePolicy" Version="2.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.1.1" />
<PackageReference Include="Microsoft.AspNetCore.HttpsPolicy" Version="2.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.RazorPages" Version="2.1.2" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.1.1" />
</ItemGroup>
</Project>
Save and close.
Try running project.
The PackReferences is just the NuGet files, and you can add them through the GUI if the versions are different from mine above.
There's lots of similar answers here, but I didn't see one that was quite what I ended up doing, so I'd like to leave this here just in case someone else is in the same shoes.
Just to be clear, my project was a console program. So, if you're trying to use this answer for something else, your mileage may vary.
In your .csproj file, inside of the <PropertyGroup></PropertyGroup> tag, modify <TargetFramework> to reflect the following:
<TargetFramework>net461</TargetFramework>
Now, in this example, I was using v4.6.1. I can only assume that you'll plug in your version behind the word "net", without the periods. Good luck!
None of the answers here worked for me. In .Net Core 2 the project.json file no longer exists. However, I did solve this problem using the following steps.
1) I removed all nuget packages from my existing project.
2) I created a separate .net core web app project, targeting .net 4.61. This was to get the default nuget packages.
3) I edited the temporary project's .csproj file, copied all the PackageReference nodes inside ItemGroup, and pasted them into my existing projects .csproj file.
4) Edited the TargetFramework node (inside PropertyGroup) from "netstandard2" to "net461"
I had a few package changes to track down and resolve, but otherwise I was able to run.
In my version of Visual Studio 2017 (15.6.2) after 'Unloading the Project', right-clicking and selecting 'Edit <your project file>, I had to:
Add the node:
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
Delete the nodes:
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
<TargetPlatformVersion Condition=" '$(TargetPlatformVersion)' == '' ">10.0.16299.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.16299.0</TargetPlatformMinVersion>
<ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
There are several steps that you need to do, in order to achieve this.
Firstly right click on the .csproj file and add the following
<TargetFrameworks>netstandard2.0;netcoreapp2.0;net35;</TargetFrameworks>
<RuntimeIdentifiers>win7-x86;win7-x64</RuntimeIdentifiers> <EnableDefaultCompileItems>false</EnableDefaultCompileItems>
Once you have made these changes reload the project and build it.
This will generate the .dll files and Nuget package for this
build in the Debug/Release folder of the project.
Add these .dll to the nuget and access these projects from
nuget.
Try the above steps. This should work.
My .net standard project is relatively simple with few Nuget packages. I just changed
<TargetFramework>netstandard2.0</TargetFramework>
TO
<TargetFramework>**net461**</TargetFramework> under PropertyGroup section of .csproj file and this did the job for me.. Thanks to Brandon Barkley for your answer in the comments.
add below in csproj
<PropertyGroup>
<TargetFrameworks>netcoreapp2.1;net471</TargetFrameworks>
</PropertyGroup>
I had only a handful of source files. For me it worked best by
Closing Visual Studio 2022
Renaming away the solution folder
Creating a new Visual Studio solution of type "WPF App (.NET Framework)" with the original folder name and same project name
Copying all *.xaml. *.xaml.cs and *.cs from the old project to the new, not touching *.sln, *.csproj and *.config.
Project->Add Existing Item… and adding the copied items
Adding all the special references.
That rebuilt all without a complaint.