Force project references to be included in netstandard nuget package - visual-studio-2017

I have a netstandard project which includes two project references. Visual studio 2017 is being used to build the nukpg. When the project is built the produced nupkg only contains the assembly produced by that project and lists the two project references as nuget dependencies. Is there a way to force the packaging to include those assemblies as lib files?
csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net462</TargetFramework>
<RootNamespace>Verifier.Observations.DevOps.Health</RootNamespace>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<VersionPrefix>1.0.1</VersionPrefix>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Verifier.Observations.Aspects\Verifier.Observations.Aspects.csproj" />
<ProjectReference Include="..\Verifier.Observations\Verifier.Observations.csproj" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.ComponentModel.Composition"/>
<Reference Include="System.Net.Http" />
</ItemGroup>
</Project>
Update
Based upon feedback from #alexgiondea-msft the package is now created as desired using the following
csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<VersionPrefix>1.0.1</VersionPrefix>
<TargetFramework>net462</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<NuspecFile>Verifier.Observations.DevOps.Health.Nuspec</NuspecFile>
<NuspecProperties>version=$(VersionPrefix);id=$(MSBuildProjectName);author=$(Authors);copy=$(Copyright);iconUrl=$(PackageIconUrl)</NuspecProperties>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Verifier.Observations.Aspects\Verifier.Observations.Aspects.csproj" />
<ProjectReference Include="..\Verifier.Observations\Verifier.Observations.csproj" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.Net.Http" />
</ItemGroup>
</Project>
nuspec
<package >
<metadata>
<id>$id$</id>
<version>$version$</version>
<title>$title$</title>
<authors>$author$</authors>
<owners>$author$</owners>
<iconUrl>$iconUrl$</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Inspect automation service to ensure it is up and operational</description>
<releaseNotes></releaseNotes>
<copyright>$copy$</copyright>
<tags>verifier-observation-plugin automation</tags>
<dependencies>
<group targetFramework="net462" />
</dependencies>
<references>
<group targetFramework="net462">
<reference file="Verifier.Observations.DevOps.Automation.dll" />
</group>
</references>
</metadata>
<files>
<file src="bin\*\net462\*.dll" target="lib\net462" />
<file src="bin\*\net462\*.pdb" target="lib\net462" />
</files>
</package>

You can control where assemblies are deployed in the nuget package using an item in an itemgroup, similar to this:
<ItemGroup>
<None Include="!!path_to_assembly!!">
<PackagePath>lib\net462</PackagePath>
<Pack>true</Pack>
<Visible>false</Visible>
</None>
</ItemGroup>
That should include the specified assembly in the package.

You can add the following target to your .csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net47</TargetFrameworks>
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);CopyProjectReferencesToPackage</TargetsForTfmSpecificBuildOutput>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\ClassLibrary2\ClassLibrary2.csproj" PrivateAssets="all" />
<ProjectReference Include="..\ClassLibrary3\ClassLibrary3.csproj" Condition="'$(TargetFramework)' == 'net47'" PrivateAssets="all" />
</ItemGroup>
<Target Name="CopyProjectReferencesToPackage" DependsOnTargets="ResolveReferences">
<ItemGroup>
<BuildOutputInPackage Include="#(ReferenceCopyLocalPaths->WithMetadataValue('ReferenceSourceTarget', 'ProjectReference'))" />
</ItemGroup>
</Target>
</Project>
Source 1
Source 2
Reference: Advanced extension points to create customized package

Related

error MSB8052: MSVC Toolset Version '14.28.29333' is not compatible with 'v120' Platform Toolset

I have been facing this issue since long, I am trying to build a project in VS 2019 which has previously built fine in vs 2013. I am facing this error which has no definition anywhere on Microsoft forums.
I have tried doing all the retargeting with the 2019 toolset as well as changing the toolset version to current in the project configuration file with no success at all.
I am not sure why even microsoft forums doesnot have any explanation for this error code (error MSB8052)
Also, the project still shows visual studio 2013 written in brackets in front of the project name. I have changed all the toolset to use the 2019 version but this is not changing.
The error is as follows : error MSB8052: MSVC Toolset Version '14.28.29333' is not compatible with 'v120' Platform Toolset. Please either change Platform Toolset to v142 or MSVC Toolset Version (VCToolsVersion property) to the version with the format '12.0*.*'. To use default MSVC Toolset Version for a given Platform Toolset don't set VCToolsVersion property.
I don't know somehow, it is still using the old platform toolset. Can somebody help me with this ?
enter code here
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Matrix">
<MatrixProjectDir>..\..\..</MatrixProjectDir>
</PropertyGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{173A4A3E-C861-4013-9366-08716BF7BCCD}</ProjectGuid>
<RootNamespace>LogicNpcUnmanagedSupport</RootNamespace>
<SccProjectName>SAK</SccProjectName>
<SccAuxPath>SAK</SccAuxPath>
<SccLocalPath>SAK</SccLocalPath>
<SccProvider>SAK</SccProvider>
<Keyword>Win32Proj</Keyword>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseOfMfc>Dynamic</UseOfMfc>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v142</PlatformToolset>
<CLRSupport>true</CLRSupport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseOfMfc>Dynamic</UseOfMfc>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v142</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\..\..\Build\PropertySheets\MatrixReleaseSettings.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\..\..\Build\PropertySheets\MatrixDebugSettings.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.40219.1</_ProjectFileVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<RunCodeAnalysis>true</RunCodeAnalysis>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<AdditionalIncludeDirectories>..\Include;$(ProjectDir)\..\..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;_COMPILING_NPC_LIB_;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Lib>
<OutputFile>$(OutDir)ag$(ProjectName).lib</OutputFile>
<TargetMachine>MachineX64</TargetMachine>
</Lib>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<AdditionalIncludeDirectories>..\Include;$(ProjectDir)\..\..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;_COMPILING_NPC_LIB_;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Lib>
<OutputFile>$(Configuration)\ag$(ProjectName).lib</OutputFile>
<TargetMachine>MachineX64</TargetMachine>
</Lib>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="agGuid.cpp" />
<ClCompile Include="agLogicNpcBuffer.cpp" />
<ClCompile Include="agLogicNpcCallForwarder.cpp" />
<ClCompile Include="agLogicNpcClient.cpp" />
<ClCompile Include="agLogicNpcDispatcher.cpp" />
<ClCompile Include="agLogicNpcException.cpp" />
<ClCompile Include="agLogicNpcHeader.cpp" />
<ClCompile Include="agLogicNpcServer.cpp" />
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="agArrayWrapper.h" />
<ClInclude Include="agArrayWrapperComposite.h" />
<ClInclude Include="agArrayWrapperPrimitive.h" />
<ClInclude Include="agGuid.h" />
<ClInclude Include="agLogicNpcBuffer.h" />
<ClInclude Include="agLogicNpcCallForwarder.h" />
<ClInclude Include="agLogicNpcClient.h" />
<ClInclude Include="agLogicNpcContentFlags.h" />
<ClInclude Include="agLogicNpcDispatcher.h" />
<ClInclude Include="agLogicNpcException.h" />
<ClInclude Include="agLogicNpcHeader.h" />
<ClInclude Include="agLogicNpcServer.h" />
<ClInclude Include="agLogicNpcServerInfo.h" />
<ClInclude Include="agLogicNpcTransport.h" />
<ClInclude Include="stdafx.h" />
<ClInclude Include="targetver.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
enter code here - MatrixDebugSettings.props
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets">
<Import Project="MatrixBaseSettings.props" />
<Import Project="MatrixMultiProcessorOptionSetting.props" />
<Import Project="MatrixDebugBaseSettings.props" />
</ImportGroup>
<PropertyGroup>
<_ProjectFileVersion>10.0.40219.1</_ProjectFileVersion>
</PropertyGroup>
</Project>
enter code here - Microsoft.Cpp.x64.user.props
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets">
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup />
<ItemDefinitionGroup />
<ItemGroup />
</Project>
You can directly open vcxproj file, then confirm and modify Platform Toolset to V142
If it doesn't work, you could try to delete .vs folder which is next to your sln file.

Can ItemGroups in new VisualStudio 2017 csproj files be merged?

For example, I have a .csproj file with the following structure:
...
<ItemGroup>
<Compile Include="...">
<Link>...</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<PackageReference Include="..." Version="..." />
</ItemGroup>
... there may even be some other tags in between ItemGroups ...
<ItemGroup>
<ProjectReference Include="..." />
</ItemGroup>
<ItemGroup>
<Reference Include="...">
<HintPath>...</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<None Update="...">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
... There may be even more additional ItemGroups with other content ...
...
Can I merge them all into one, something like this?
...
<ItemGroup>
<PackageReference Include="..." Version="..." />
<ProjectReference Include="..." />
<Compile Include="...">
<Link>...</Link>
</Compile>
<Reference Include="...">
<HintPath>...</HintPath>
</Reference>
<None Update="...">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
...
I've done it, there seem to be no problem from what I observe at the moment, but I don't want me or other developers to run into them later, not knowing they may be linked to this action.
Merging them is no problem, it is equivalent from the MSBuild API.
However, some tooling may look for item groups containing only specific things (e.g. NuGet wants to add to item groups that already contain package references), but that means that in the worst case, tools may add additional item groups.

dotnet core, VS2017 15.5.4 is not publishing static html/js files from Ui folder

dotnet core 2.x, VS2017 15.5.4 is not publishing static html/js files from Ui folder.
We've combined out dotnet core Web Api and our Client UI, Aurelia into the same project. When I publish the Aurelia files are not being copied out, only the files in the Aurelia that are json. I thought I could right click the files and folders and set the Build Action property to Content but I get an error, see last image.
Here is my .csproj file
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<AssemblyName>Web</AssemblyName>
<RootNamespace>Web</RootNamespace>
<TypeScriptToolsVersion>2.5</TypeScriptToolsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="2.0.0" />
<PackageReference Include="Microsoft.Graph" Version="1.6.2" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.0" PrivateAssets="All" />
<PackageReference Include="Serilog.AspNetCore" Version="2.1.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="2.4.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
<PackageReference Include="Serilog.Sinks.RollingFile" Version="3.3.0" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
<DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="2.0.0" />
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.00" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Common\Common.csproj" />
<ProjectReference Include="..\Lms\Lms.Service.csproj" />
</ItemGroup>
<ItemGroup>
<Content Update="appsettings.Development.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>
Error when right clicking and click Properties from the menu I get this

Obtain a reference of Microsoft.CodeAnalysis.Project loaded from ProjectFile in netstandard

I try to port some code to netstandard so it can run on Linux.
Previosly I used MSBuildWorkspace to optain a workspace and load a Project.
MSBuildWorkspace workspace = MSBuildWorkspace.Create();
Microsoft.CodeAnalysis.Project project = await workspace.OpenProjectAsync(projectPath);
When I switched to netstandard there was no longer a MSBuildWorkspace. How do I get a Project instance file from a .csproj file.
EDIT
That's the project file with all packages I reference.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="15.5.180" />
<PackageReference Include="Microsoft.CodeAnalysis" Version="2.6.1" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="2.6.1" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="2.6.1" />
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="2.6.1" />
<PackageReference Include="Microsoft.DotNet.ProjectModel" Version="1.0.0-rc3-1-003177" />
</ItemGroup>
</Project>
MSBuildWorkspace will be included in a seperate package. See this issue

Unable to Build/Run Multiple Frameworks Using VS 2017's Csproj

I'm using the JavaScript Services Angular infrastructure to build an Angular project that utilizes Entity Framework. I was able to produce a similar project in the past by modifying the project.json file but project settings are now set in the csproj file in VS2017. Below is my code based on Microsoft's recommendations for adapting project.json files to csproj:
<Project ToolsVersion="15.0" Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework> <-- Tried with and without ths line -->
<TargetFrameworks>netcoreapp1.1;net452</TargetFrameworks>
<RuntimeIdentifiers>win7-x64</RuntimeIdentifiers>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net452'">
<PackageReference Include="EntityFramework" Version="6.1.3" />
<PackageReference Include="Microsoft.CSharp" Version="1.0.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp1.1'">
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.0" />
</ItemGroup>
<ItemGroup>
...
On Build I get the following error referencing several files in my project:
Error CS0012 The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
With the <TargetFramework> tag removed, no netcoreapp1.1 references were found.