I maintain a few tiny Nuget Packages.
I have a Nuget README file in the git repository, and the .nupkg file is auto-built by VS, based on the "Package" config, stored in the .csproj file.
Whenever I need to release a new versio of the package, I upload the .nupkg file to nuget, in the web UI, and then it asks me for any documentation, at which point I have to manually upload the README file.
Is there any way to put that README file in the .nupkg so that I don't have to manually upload it every time?
NuGet have now added support to make this JustWork.
Announcement on the Issue thread: https://github.com/NuGet/Home/issues/6873#issuecomment-833829727
Announcement Blog post: https://devblogs.microsoft.com/nuget/add-a-readme-to-your-nuget-package/
All you need to do is reference the README.md file in the .csproj, using the PackageReadmeFile tag. If the README.md is in the git root (i.e. where GitHub auto-detects it) then it will look like this:
<PackageReadmeFile>README.md</PackageReadmeFile>
Currently there is not a way to do this, but it is WIP.
The new spec under review: https://github.com/NuGet/Home/wiki/Embedding-and-displaying-NuGet-READMEs
This issue for this feature: https://github.com/NuGet/Home/issues/6873
i do this via the csprj. file.
I created a .netstandard project and added a readme.txt.
add following to the x.csproj
<ItemGroup>
<None Include="readme.txt" pack="true" PackagePath="." />
</ItemGroup>
When installing the nuget the first time the file will be displayed in VS.
There is somewhere in the internet a artikel describing the solution, but i cannot find it now.
Here my complete csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net471;net35</TargetFrameworks>
.....
<FileVersion>1.0.1.11</FileVersion>
<AssemblyVersion>1.0.1.11</AssemblyVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NLog" Version="4.7.6" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="readme.txt" pack="true" PackagePath="." />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
</Project>
Related
unfortunately the PC I am working with has no Internet Connection and only Visual Studio Code. So far I have not been able to install the microsoft.entityframeworkcore.3.1.4.nupkg package. So I was thinking about just using the dll but keep everything else in the project like usual.
In my class I want to call:
using Microsoft.EntitiyFrameworkCore;
my csproj file looks like this:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" />
</ItemGroup>
<Reference Include="Microsoft.EntityFrameworkCore">
<HintPath>..\Framework\Microsoft.EntityFrameworkCore.dll</HintPath>
</Reference>
</Project>
I also copied the dll to the debug and release folder, as well as the Framework folder. Can someone give me a hint what I am missing? I assume locally add the nupkg package just by a command line without internet and without the full version of Visual Studio is impossible.
Thanks
Stephan
I think I forgot the itemgroup:
<ItemGroup>
<Reference Include="Microsoft.EntityFrameworkCore">
<HintPath>\Framework\Microsoft.EntityFrameworkCore.dll</HintPath>
</Reference>
</ItemGroup>
I have a config file in a .netstandard2.0 project, and I'd like to include it in the same directory when packing, I already have this in csprof file:
<ItemGroup>
<None Include="load.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
and when I build it with dotnet build, the config file indeed was copied to output directory, but when dotnet pack, the nugget only includes the .dll, not the .config file, how can I include this config file in nugget package?
Try to add Pack="true" property:
<ItemGroup>
<None Include="load.config" Pack="true">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
You may also need to specify PackagePath property as well. I have found sample in files section.
I've setup building nuget package from my project using package tab in project options. Everything seems to work except that my nuget package contains stylecop.json file. Build action for this file is set to "C# analyzer additional file". How to get rid of this file from nuget package?
This is my csproj file content
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageLicenseUrl>https://github.com/aixasz/ImageShareTemplate/blob/develop/LICENSE</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/aixasz/ImageShareTemplate/</PackageProjectUrl>
<Description>ImageShareTemplate is image template library to share an image to social like facebook, twitter, etc.</Description>
<RepositoryUrl>https://github.com/aixasz/ImageShareTemplate/</RepositoryUrl>
<PackageTags>image socialmedia</PackageTags>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.0-beta0001" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta0001" />
</ItemGroup>
<ItemGroup>
<Folder Include="Fonts\" />
</ItemGroup>
</Project>
I have created a test project based on .Net Core 2 and wrote some NUnit test cases. After installing necessary NuGet packages i.e. NUnit3TestAdapter, I was able to see all test cases in "Test Explorer" and able to execute those. Now, when I looked into the project directory, I found that it's creating "obj" folder and some json files in it. So I tried to change the path of "obj" folder by modifying ".csproj" file. I provided some different path in the parameter "BaseIntermediateOutputPath" and that way, I was able to get rid of "obj" folder. The reason for providing different path was, I wanted to keep json files separate from source code.
However, after modifying that I am not able to see or execute any test cases from Test Explorer.
Is this a Microsoft bug?
Is any packages having dependency on "obj" folder?
P.S.
I am using "NUnit" and "NSubstitute" packages for my test project.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<TargetFramework>netcoreapp2.0</TargetFramework>
<OutputPath>..\..\build\$(Configuration)\UnitTests\</OutputPath>
<BaseIntermediateOutputPath>..\..\work\$(MSBuildProjectName)\</BaseIntermediateOutputPath>
</PropertyGroup>
<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />
<ItemGroup>
<PackageReference Include="Castle.Core" Version="4.1.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
<PackageReference Include="NSubstitute" Version="2.0.3" />
<PackageReference Include="NUnit" Version="3.8.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.8.0" />
</ItemGroup>
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
<ItemGroup>
<ProjectReference Include="..\UtilityLibrary\UtilityLibrary.csproj" />
</ItemGroup>
</Project>
When .NET Core projects build, they do not copy all referenced files into the bin folder. When you add Microsoft.NET.Test.Sdk to your test project, one of the things it does is add an AssemblyResolve event handler which loads other dependent assemblies from a list of searchDirectories.
BaseIntermediateOutputPath not working was reported against the VSTest project and is an issue with MSBuild. The workaround is noted in the dotnet sdk repository. From that, you need to use Sdk imports in your csproj instead of the Sdk attribute on the Project element.
<Project>
<PropertyGroup>
<BaseIntermediateOutputPath>obj\XXX\</BaseIntermediateOutputPath>
</PropertyGroup>
<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />
<!-- Body of project -->
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
</Project>
.nuspec file has section <files>, what are the alternatives for include localization resources for new csproj file? How to add custom DLL files?
The first part of the trick is to get your third party DLL added to the nupkg. This does it:
<ItemGroup>
<Reference Include="ThirdParty">
<HintPath>..\DLLs\ThirdParty.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Content Include="$(OutputPath)\ThirdParty.dll">
<Pack>true</Pack>
<PackagePath>lib\$(TargetFramework)</PackagePath>
</Content>
</ItemGroup>
If you install this package into an old-style csproj then a reference to ThirdParty.dll will be added.
However, if you install this package into a new-style csproj then a reference to ThirdParty.dll will not be added as a referece, irritatingly. Work in progress...