Installed NuGet throws System.IO.FileNotFoundException - c#

Creating classlibrary and trying to install Markdig.
I can use usings in code, but I'm trying to start debugging and it throws it:
link to library.
https://github.com/xoofx/markdig
Here is my .csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<RootNamespace>Kvyk.Telegraph.Markdown</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Kvyk.Telegraph" Version="1.0.2" />
<PackageReference Include="Markdig" Version="0.25.0" />
</ItemGroup>
</Project>

Related

How to make VS to copy nuget packages dll's to output directory

I'm trying to use material design in the first time on my WPF project I install the package from nuget but when I'm trying torun it it's prompt:
System.Windows.Markup.XamlParseException: 'Could not load file or
assembly 'MaterialDesignThemes.Wpf, Culture=neutral,
PublicKeyToken=df2a72020bd7962a'. The system cannot find the file
specified.'
When I'm copying the assemblies manually to the output folder it's works.
My .csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<BaseOutputPath>$(SolutionDir)\bin\</BaseOutputPath>
<OutputPath>$(SolutionDir)\bin\</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
<UseCommonOutputDirectory>true</UseCommonOutputDirectory>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MaterialDesignThemes" Version="4.6.1" />
<PackageReference Include="ShowMeTheXAML.MSBuild" Version="2.0.0" />
</ItemGroup>
</Project>
I tried to add
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
but it does nothing.
Here is my .csproj
<Project Sdk="Microsoft.NET. Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MaterialDesignThemes" Version="4.6.1" />
</ItemGroup>
</Project>
Auto copy is fine. Your problem did not occur. Have you tried recreating a project, does the same problem occur?
If that still doesn't work, you may need to add the msbuild event to copy the file. Use xcopy.

Serilog not installing in Library project .Net 6

I have a Library project in .net6, I have attempted to install serilog version 2.10 or serilog.AspCore version 5.0 a couple of time but both returned error. I keep getting errorPackage Serilog.Sinks.Debug 2.0.0 is not compatible with net6.0 each time. Below is the .csproj file.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.3" />
</ItemGroup>
</Project>
Does this mean serilog is not available for .net6 library project or I am not getting the version right?
I have tried the following project setup and works fine for me:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.3" />
<PackageReference Include="Serilog" Version="2.10.0" />
<PackageReference Include="Serilog.Sinks.Debug" Version="2.0.0" />
</ItemGroup>
</Project>

How to NOT pack a C# source generator and NOT upload it to NuGet?

I created a class library and uploaded it to NuGet.org.
The class library uses a C# source generator to generate repetitive code (e.g. methods using value tuples).
The class library lives a happy life on NuGet.org, but, somehow, the source generator project got packaged and uploaded as well, which isn't what I wanted...
How to prevent a source generator project from being uploaded to NuGet?
The .csproj of the class library:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<PropertyGroup>
<!-- Version, Authors, Description and other NuGet package info abbreviated here. -->
</PropertyGroup>
<ItemGroup>
<ProjectReference
Include="..\MyLib.SourceGenerators\MyLib.SourceGenerators.csproj"
OutputItemType="Analyzer"
ReferenceOutputAssembly="false"/>
</ItemGroup>
</Project>
The .csproj of the source generator:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>9.0</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.8.0"/>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
Adding <IsPackable>false</IsPackable> to the .csproj of the source generator project seems to prevent a NuGet package from being generated, similar to unit test projects.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>9.0</LangVersion>
<IsPackable>false</IsPackable> <!-- HERE -->
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.8.0"/>
<!-- ... -->

.NET Core 2.0 Project Builds But Not When Referenced By Another .NET Core 2.0 Project

I'm on Ubuntu and I have two .NET Core 2.0 projects (Project Oranges.csproj and Apples.csproj). Oranges only contains references to NuGet packages, while Apples contains a reference to Oranges.
Running dotnet build -f netcoreapp2.0 Oranges.csproj succeeds! Oranges.dll now exists at /Oranges/bin/Debug/netcoreapp2.0/Oranges.dll.
Running dotnet build -f netcoreapp2.0 Apples.csproj fails with: error CS0009: Metadata file '/Oranges/bin/Debug/netcoreapp2.0/Oranges.dll' could not be opened -- PE image doesn't contain managed metadata
How can I go about referencing Oranges, which builds without issue, in Apples without issue?
Oranges.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<TargetFrameworks>netcoreapp2.0;net451;</TargetFrameworks>
<RootNamespace>Oranges</RootNamespace>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\GeneratedKey.snk</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'netcore2.0'">
<DefineConstants>NETCORE2_0</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'net451'">
<DefineConstants>NET4_5_1</DefineConstants>
</PropertyGroup>
<ItemGroup>
<None Remove="packages.config" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
</ItemGroup>
</Project>
Apples.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<TargetFrameworks>netcoreapp2.0;net451;</TargetFrameworks>
<RootNamespace>Apples</RootNamespace>
<SignAssembly>true</SignAssembly>
<DelaySign>false</DelaySign>
<AssemblyOriginatorKeyFile>..\..\GeneratedKey.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<None Remove="packages.config" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.1.1-beta" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
<PackageReference Include="System.Composition" Version="1.1.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Oranges\Oranges.csproj" />
</ItemGroup>
</Project>
After deleting the bin and obj folders from the project directory and rebuilding, a different error was being displayed.
CSC : error CS7027: Error signing output with public key from file 'GeneratedKey.snk' -- Assembly signing not supported. [.../Oranges/Oranges.csproj]
After some research I stumbled across a solution.
Assembly Signing Not Supported
Adding the line below to the .csproj file for each assembly that required signing resolved the issue.
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
For now it seems like if you need to sign netcore assemblies, it should be done on Windows.

How can I specify /debug:embedded from csproj?

I've authored a dotnet core library, which is packaged using NuGet. I want to embed the debug information (and the source code if that's possible) in the dll. rather than have a separate symbols package.
According to https://github.com/ctaggart/SourceLink it looks like this is possible when invoking the compiler directly by specifying some switches to the compiler. I don't understand how the csproj file relates to invocation of the compiler.
How can I specify the flag /debug:embedded from the csproj?
Here's my csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard1.6</TargetFramework>
<AssemblyName>KamailioApi</AssemblyName>
<PackageId>KamailioApi</PackageId>
<PackageTargetFallback>$(PackageTargetFallback);dnxcore50</PackageTargetFallback>
<NetStandardImplicitPackageVersion>1.6.1</NetStandardImplicitPackageVersion>
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
<GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute>
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
<!-- don't change this we hack it in the TeamCity Build-->
<Version>1.0.1</Version>
<PackageVersion>1.0.1-beta</PackageVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
<PackageReference Include="System.Runtime.Serialization.Formatters" Version="4.3.0" />
<PackageReference Include="System.Xml.XmlDocument" Version="4.0.1" />
<PackageReference Include="system.xml.xpath.xmldocument" Version="4.0.0" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.6' ">
<PackageReference Include="System.Net.Requests" Version="4.3.0" />
</ItemGroup>
</Project>
You can do this with the <DebugSymbols> and <DebugType> properties, like this:
<PropertyGroup>
<DebugSymbols>true</DebugSymbols>
<DebugType>embedded</DebugType>
</PropertyGroup>
Here's an example of where I do it with MiniProfiler, note that Directory.build.props applies to all .csproj files at or below that directory level so you can specify common things in larger projects one time.

Categories

Resources