How can I include the entire build output in a nuget package programatically using GeneratePackageOnBuild - visual-studio

I'm using <GeneratePackageOnBuild>True</GeneratePackageOnBuild> to get Visual Studio to automatically build a Nuget package when I build my project. But this package is being used as a plugin to another project. So I've included <EnableDynamicLoading>True</EnableDynamicLoading>. This causes all of the dependency DLLs to be copied to the build output folder. So far so good.
The problem is that when Visual Studio builds the Nuget package, only the main project dll is included in the package. How do I get Visual Studio to include all of the build output files in the Nuget package?
Here is my project file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Version>1.2.6</Version>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<EnableDynamicLoading>True</EnableDynamicLoading>
<PackageId>ProjectName</PackageId>
<DebugSymbols>true</DebugSymbols>
<DebugType>embedded</DebugType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Package1" Version="3.1.0">
<Private>false</Private>
<ExcludeAssets>runtime</ExcludeAssets>
</PackageReference>
<PackageReference Include="Package2" Version="1.0.1" PrivateAssets="All" />
<PackageReference Include="Package3" Version="1.0.4" PrivateAssets="All" />
</ItemGroup>
</Project>
I want my nuget package to include: ProjectName.dll, Package2.dll, and Package3.dll

Related

Blazor Webassembly Load failed - Something with Dotnet sdk

So my project doesn't load (unloaded/load failed).
I get this message in my output window:
C:\Users\username\source\repos\MyProject\MyProject.csproj : error : The project file cannot be opened. C:\Program Files\dotnet\sdk\3.1.403\Sdks\Microsoft.NET.Sdk.BlazorWebAssembly\Sdk not found. Check that a recent enough .NET Core SDK is installed and/or increase the version specified in global.json.
I have the newest Version of VS2019:
I allowed the use of previews of the .NET Core SDK
SDK 3.1.403 is installed.
My Project has no global.json. I tried to create global.json in my root folder.
{
"sdk": {
"version": "3.1.403"
}
}
but it also did not work.
I downloaded and installed both .NET Core SDK x64 and x86.
My .csproj
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<ServiceWorkerAssetsManifest>service-worker-assets.js</ServiceWorkerAssetsManifest>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.0-rc.2.20475.17" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="5.0.0-rc.2.20475.17" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="5.0.0-rc.2.20475.17" />
<PackageReference Include="System.Net.Http.Json" Version="5.0.0-rc.2.20475.5" />
</ItemGroup>
<ItemGroup>
<ServiceWorker Include="wwwroot\service-worker.js" PublishedContent="wwwroot\service-worker.published.js" />
</ItemGroup>
</Project>
I restarted VS2019 and my Device everytime I changed anything.
Please help. I'm desperate. How can I work on this Solution?

.NET Standard Project File Format for Analyzers

I don't have access to NuGet currently, and I need to add a Roslyn analyzer (StyleCop) to a new .NET Standard class library project. What manual file edits (project.csproj, package.config) do I need to make? I already have the StyleCop nuget package downloaded from installing it in a .NET Framework class library earlier.
If you already have the StyleCop package in your NuGet cache, what you posted in your answer will work and it will work if you clear your cache when have access to NuGet.org.
But if you have an analyzer library that is not on a NuGet package that you want to use, you can explicitly add analyzers:
<ItemGroup>
<Analyzer Include="<path to analyzer dll" />
</ItemGroup>
Looked at an existing .NET Standard class library project with StyleCop installed. Here's the relevant portions of the project file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard1.4</TargetFramework>
...
</PropertyGroup>
...
<ItemGroup>
<AdditionalFiles Include="stylecop.json" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>
...
</Project>

Angular-cli project, hosted inde a Visual Studio Core 2.2 Web Api project, fails to compile, randomly

I have a Visual Studio 2017 ASP.NET Core 2.2 project based on the API template.
Inside the Api project I have created a new angular-cli based web application.
Visual Studio Build fails to compile randomly. Build fails. Then I compile again without changing anything and the build completes successfully. If I build again, it will now compile consistently but with warningss, and suddenly it will start fail again with same errors and repeat.
When it fails I get 24 build errors similar to this. It package folder under nodes_modules.
TS2420 Build:Class 'MockMediaQueryList' incorrectly implements interface 'MediaQueryList'. C:\somePath\node_modules\#angular\flex-layout\core\typings\match-media\mock\mock-match-media.d.ts
When it compiles I have 8 warnings like this:
C:\somePath\node_modules\#angular\flex-layout\core\typings\match-media\mock\mock-match-media.d.ts(62,22): error TS2420: Build:Class 'MockMediaQueryList' incorrectly implements interface 'MediaQueryList'.
I am not aware of anything that is doing any operations on the files under node_modules at compile time. The angular-cli app should be completely ignored by MsBuild, but it is clearly not.
Under "project properties" --> "Typescript build" I have selected "Use latest available" and removed the checkmark in the "Enable" checkbox.
This is my project.csproj file
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<IsServiceFabricServiceProject>True</IsServiceFabricServiceProject>
<ServerGarbageCollection>True</ServerGarbageCollection>
<RuntimeIdentifier>win7-x64</RuntimeIdentifier>
<TargetLatestRuntimePatch>False</TargetLatestRuntimePatch>
<TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.ServiceFabric.AspNetCore.Kestrel" Version="3.3.617" />
</ItemGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<TypeScriptTarget>ES2015</TypeScriptTarget>
<TypeScriptJSXEmit>None</TypeScriptJSXEmit>
<TypeScriptModuleKind>ES6</TypeScriptModuleKind>
<TypeScriptCompileOnSaveEnabled>False</TypeScriptCompileOnSaveEnabled>
<TypeScriptNoImplicitAny>False</TypeScriptNoImplicitAny>
<TypeScriptRemoveComments>True</TypeScriptRemoveComments>
<TypeScriptOutFile />
<TypeScriptOutDir />
<TypeScriptGeneratesDeclarations>False</TypeScriptGeneratesDeclarations>
<TypeScriptNoEmitOnError>True</TypeScriptNoEmitOnError>
<TypeScriptSourceMap>True</TypeScriptSourceMap>
<TypeScriptMapRoot />
<TypeScriptSourceRoot />
</PropertyGroup>
</Project>
The problem was resolved by upgrading to the latest version
npm install #angular/flex-layout#latest

Code Coverage for .NET Core 2.0 projects in Visual Studio 2017

Version: 15.4.1 - Visual Studio Enterprise 2017
I created a simple .NET Core 2.0 library project and added a UnitTest Project to it. When I run Test -> Analyze Code Coverage -> All tests. Code Coverage Results only report the code coverage for the unit test project.
I already configured the project according to Working with Code Coverage. This is my .csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<IsPackable>false</IsPackable>
<!-- Required in both test/product projects. This is a temporary workaround for https://github.com/Microsoft/vstest/issues/800 -->
<DebugType>Full</DebugType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.2.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.2.0" />
<!-- Required. Include this reference for coverage -->
<PackageReference Include="Microsoft.CodeCoverage" Version="1.0.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ClassLibrary1\ClassLibrary1.csproj" />
</ItemGroup>
</Project>
Update:
I added the same code in the solution as .NET 4.6.2 projects and ran Code Coverage again. It covers the class library just as you would expect:
So my Visual Studio is correctly configured to run Code Coverage. At least for .NET 4.6.2. I also tried it in a fresh VS installation and in VSTS.
I created a repo with my sample code. Can anyone else reproduce this?
There is a workaround that I didn't fully understand.
You have to add <DebugType>Full</DebugType> to all the projects that you need to cover. Not the unit test itself.

How to change “Class Library Project” into “Test Project"?

While working on ASP.NET MVC3 application, by mistake I have added a Class library as a Unit Test project. But unfortunately I don’t see the "Run Tests" from context menu to test the methods which are created for unit testing .
Is there any way to convert the “Class Library Project” into a “Test Project” ?
There is a property type guid in the project file.
Look at this post: How does Visual Studio /mstest identify test projects?
add Microsoft.NET.Test.Sdk from nuget
What worked for me was to do add this <PropertyGroup> tag with this libraries to my project (.csproj or .vbproj) file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.7" />
<PackageReference Include="coverlet.collector" Version="1.3.0" />
</ItemGroup>
<!--Here goes any other configuration-->
</Project>

Resources