NSWAG update to .NET6 - .NETPlatform,Version=v6.0 not found - c#

I've updated all projects in my solution to use .net6, and have updated nswag json file to runtime to Net60.
I have .net 6.0.100 installed.
Here is the build output
$ dotnet build Solution.sln
Microsoft (R) Build Engine ersion 17.0.0+c9eb9dd64 for .NET
Restored C:\src\...\Client.csproj (in 455 ms).
NSwag command line tool for .NET Core Net60, toolchain v13.15.10.0 (NJsonSchema v10.6.10.0 (Newtonsoft.Json v13.0.0.0))
NSwag bin directory: C:\Users\...\.nuget\packages\nswag.msbuild\13.15.10\tools\Net60
Executing file 'nswag.json' with variables 'Configuration=Debug'...
C:\Program Files\dotnet\sdk\6.0.100\Microsoft.Common.CurrentVersion.targets(1217,5): error MSB3644: The reference assemblies for .NETPlatform,Version=v6.0 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks [C:\src\API.csproj] [C:\src\...\.Client.csproj]
System.InvalidOperationException: Unable to retrieve project metadata. Ensure it's an MSBuild-based .NET Core project.If you're using custom BaseIntermediateOutputPath or MSBuildProjectExtensionsPath values, Use the --msbuildprojectextensionspath option.
at NSwag.Commands.Generation.AspNetCore.ProjectMetadata.GetProjectMetadata(String file, String buildExtensionsDir, String framework, String configuration, String runtime, Boolean noBuild, String outputPath, IConsoleHost console) in /_/src/NSwag.Commands/Commands/Generation/AspNetCore/ProjectMetadata.cs:line 152
C:\src\....Client.csproj(15,5): error MSB3073: The command "dotnet "C:\Users\...\.nuget\packages\nswag.msbuild\13.15.10\build\../tools/Net60/dotnet-nswag.dll" run nswag.json /variables:Configuration=Debug" exited with code -1.
C:\Program Files\dotnet\sdk\6.0.100\Microsoft.Common.CurrentVersion.targets(1217,5): error MSB3644: The reference assemblies for .NETPlatform,Version=v6.0 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks [C:\src\API.csproj] [C:\src\...\Client.csproj]
C:\src\...\.Client.csproj(15,5): error MSB3073: The command "dotnet "C:\Users\...\.nuget\packages\nswag.msbuild\13.15.10\build\../tools/Net60/dotnet-nswag.dll" run nswag.json /variables:Configuration=Debug" exited with code -1.

I did find a workaround - it gets me past the problem.
In the nswag.json file, it fails when I reference the project in the project element of
"documentGenerator": {
"aspNetCoreToOpenApi": {
"project" "../relative/path/to/.csproj",
"assemblyPaths": [
"../../bin/dotnet6.0/MyAPI.dll"
]
}
}
So remove project.
And reference the output DLL from your project in the assemblyPaths[] array.
It builds successfully & the client is regenerated.

Related

Can't locate installed package (type or namespace could not be found)

I'm trying to install a NuGet package and the installation seems to be going fine:
# D:\Dev\PGF_Test
$ dotnet add package PGFSharp --version 3.8.1-devel
Determining projects to restore...
Writing C:\Users\...\AppData\Local\Temp\tmp71D3.tmp
info : Adding PackageReference for package 'PGFSharp' into project 'D:\Dev\PGF_Test\PGF_Test.csproj'.
info : Restoring packages for D:\Dev\PGF_Test\PGF_Test.csproj...
info : Package 'PGFSharp' is compatible with all the specified frameworks in project 'D:\Dev\PGF_Test\PGF_Test.csproj'.
info : PackageReference for package 'PGFSharp' version '3.8.1-devel' added to file 'D:\Dev\PGF_Test\PGF_Test.csproj'.
info : Committing restore...
info : Generating MSBuild file D:\Dev\PGF_Test\obj\PGF_Test.csproj.nuget.g.targets.
info : Writing assets file to disk. Path: D:\Dev\PGF_Test\obj\project.assets.json
log : Restored D:\Dev\PGF_Test\PGF_Test.csproj (in 227 ms).
but when I write the using and dotnet build, I get a namespace could not be found. I've tried removing and re-adding, I've tried different names like PGF and PGFSharp.PGF, and I've tried making a fresh console application and adding it there to make sure nothing's interfering.
Anyone know what the issue might be?
I'm on .NET core on Windows 10, version 5.0.201. I checked the Github for the package I'm importing and it seems to be built in 4.5.1, could that be the issue? If so I might try recompiling the source locally.

How to build a native nuget package

I am trying to build the nuget package of the GDCM project. This project is written in C++ and offer a C# binding using SWIG.
Here is my current attempt:
This is based mostly on:
https://stackoverflow.com/a/52459363/136285
And references from:
https://learn.microsoft.com/en-us/nuget/create-packages/supporting-multiple-target-frameworks
https://learn.microsoft.com/en-us/dotnet/core/rid-catalog
When I install this nuget package in a Visual Studio 2019 test project (.NET Framework 4, on Windows 8.1) here is the error message that I get:
--EntryPointNotFoundException
at gdcm.gdcmPINVOKE.new_ImageReader()
at gdcm.ImageReader..ctor()
at My.ReadSequenceVolume(Boolean doRead) in C:\Users\malat\test\ImageVolumeReader.cs:line 17
Result Message:
My.DicomBase.ImageReaderFileException : ImageReaderFileException exception : "Unable to find an entry point named 'CSharp_gdcm_new_ImageReader' in DLL 'gdcmsharpglue'." (type=System.EntryPointNotFoundException) while reading "RGB.dcm"
----> System.EntryPointNotFoundException : Unable to find an entry point named 'CSharp_gdcm_new_ImageReader' in DLL 'gdcmsharpglue'.
Is there an issue in the hierarchy I build for this native nuget package ?
Update: Per suggestion, I tried adding Microsoft.NETCore.Platforms:
<dependencies>
<dependency id="Microsoft.NETCore.Platforms" version="1.0.0" />
</dependencies>
Which gave me:
But now my test project reports:
Severity Code Description Project File Line Suppression State
Error Could not install package 'Microsoft.NETCore.Platforms 1.0.0'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.0', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

What version of SN tool should I use for resigning .Net v3.5 interops?

There are some c++ projects(vcxproj) in my solution those really interop projects.
All was fine until I tried to re-build them for .net v3.5 (they initially target .net v4.5)
I changed the version string to "v3.5" in the project files, changed the path for ilasm to
‘C:\Windows\Microsoft.NET\Framework\v2.0.50727\ilasm.exe’
and all looks fine.
I built these projects, made a msi package and tried to install it, but got this error:
Assembly Install: Failing with hr=8013141a
Assembly Error:Strong name signature verification failed for assembly '%1'. The assembly may have been tampered with, or it was delay signed but not fully signed with the correct private key.
Product: MY_PROJECT -- Error 1937. An error occurred during the installation of assembly 'MY_PROJECT.Interop,Version="5.3.0.0",Culture="neutral", PublicKeyToken="0DC6B9046BBF1D8A",ProcessorArchitecture="MSIL"'. The signature or catalog could not be verified or is not valid. HRESULT: 0x80131045. assembly interface: IAssemblyCacheItem, function: Commit, component: {84C66D06-D31F-536F-B79F-71F7E5F4BFE3}
I checked my configuration.
I use Visual Studio 2013 and VS 2010 is installed too, and some SDKs.
VS 2013 uses OLD version of SN for signing my projects and this old version is located in the
"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\sn.exe"
Just for case I changed the path to sn tool 4.5:
"C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\sn.exe"
and my interop files were installed without any issue!
this is a sequence I use for creating key files:
sn.exe -m
sn.exe -k CONTAINER-Authenticode.snk
sn.exe -i CONTAINER-Authenticode.snk CONTAINER
sn.exe -pc CONTAINER CONTAINER-Authenticode.pbk
Added system variables SN_ContainerName=CONTAINER; SN_Option=-Rc
The my question is, why is that, what version of SN should I use, where can I read something about that, and where can I made any error.

TFS Build - C# 7.0 System.ValueType

I try to setup a continuous integration build on VisualStudio.com to build my project. Since I upgraded to .net 4.6.2 and working with the System.ValueType, the build fails:
MinimalMonitoringClient\MMCThinNetwork\Connection.cs(91,23): Error
CS1519: Invalid token '(' in class, struct, or interface member
declaration Connection.cs(91,23): error CS1519: Invalid token '(' in
class, struct, or interface member declaration
[d:\a\1\s\MinimalMonitoringClient\MMCThinNetwork\MMCThinNetwork.csproj]
MinimalMonitoringClient\MMCThinNetwork\Connection.cs(91,47): Error
CS1044: Cannot use more than one type in a for, using, fixed, or
declaration statement Connection.cs(91,47): error CS1044: Cannot use
more than one type in a for, using, fixed, or declaration statement
[d:\a\1\s\MinimalMonitoringClient\MMCThinNetwork\MMCThinNetwork.csproj]
MinimalMonitoringClient\MMCThinNetwork\Connection.cs(91,64): Error
CS1002: ; expected
It compiles on my local computer
The NuGet Package "System.ValueType" is installed
No Package Folder on TFS
The Task "Restore NuGet Packages" is included in the build process
NuGet Restore Build Step finishes successfully
2017-04-22T14:42:13.2402898Z ##[section]Starting: NuGet restore
**/*.sln 2017-04-22T14:42:13.2512895Z ============================================================================== 2017-04-22T14:42:13.2512895Z Task : NuGet Installer
2017-04-22T14:42:13.2512895Z Description : Installs or restores
missing NuGet packages 2017-04-22T14:42:13.2512895Z Version :
0.2.31 2017-04-22T14:42:13.2512895Z Author : Microsoft Corporation 2017-04-22T14:42:13.2512895Z Help : More
Information
2017-04-22T14:42:13.2512895Z
============================================================================== 2017-04-22T14:42:14.3517087Z [command]C:\Windows\system32\chcp.com
65001 2017-04-22T14:42:14.3517087Z Active code page: 65001
2017-04-22T14:42:14.4246880Z Detected NuGet version 3.3.0.212 / 3.3.0
2017-04-22T14:42:14.4276880Z SYSTEMVSSCONNECTION exists true
2017-04-22T14:42:14.4286876Z To connect to NuGet feeds hosted in your
Team Services account/TFS project collection on this build agent, edit
your build definition to choose a higher version of nuget or specify a
path to a NuGet.config containing the package sources you wish to use.
2017-04-22T14:42:14.4316868Z
[command]d:\a_tasks\NuGetInstaller_333b11bd-d341-40d9-afcf-b32d5ce6f23b\0.2.31\node_modules\nuget-task-common\NuGet\3.3.0\NuGet.exe
restore -NonInteractive
d:\a\1\s\MinimalMonitoringClient\MinimalMonitoringClient.sln
2017-04-22T14:42:15.2210188Z MSBuild auto-detection: using msbuild
version '14.0' from 'C:\Program Files (x86)\MSBuild\14.0\bin'.
2017-04-22T14:42:15.4566895Z Feeds used: 2017-04-22T14:42:15.4566895Z
C:\Users\buildguest\AppData\Local\NuGet\Cache
2017-04-22T14:42:15.4576898Z https://api.nuget.org/v3/index.json
2017-04-22T14:42:15.4576898Z 2017-04-22T14:42:15.4786896Z Restoring
NuGet package System.ValueTuple.4.3.0. 2017-04-22T14:42:15.4896877Z
Restoring NuGet package Newtonsoft.Json.10.0.2.
2017-04-22T14:42:16.5110192Z Adding package 'System.ValueTuple.4.3.0'
to folder 'd:\a\1\s\MinimalMonitoringClient\packages'
2017-04-22T14:42:16.5330192Z Added package 'System.ValueTuple.4.3.0'
to folder 'd:\a\1\s\MinimalMonitoringClient\packages'
2017-04-22T14:42:16.7550436Z Adding package 'Newtonsoft.Json.10.0.2'
to folder 'd:\a\1\s\MinimalMonitoringClient\packages'
2017-04-22T14:42:16.7780484Z Added package 'Newtonsoft.Json.10.0.2' to
folder 'd:\a\1\s\MinimalMonitoringClient\packages'
2017-04-22T14:42:16.8080211Z ##[section]Finishing: NuGet restore
**/*.sln
In Build Solution the VS Version is set to: 2017
Clean: True
Restore NuGet Packages: True
Thanks in advance
You need to use the Hosted VS2017 Build Agent to compile things using VS2017.

Mono xbuild error CS1548 - key file has incorrect format

So I'm trying to get a VS2010 C# project to go cross-platform. First goal is build it in Mono 2.10.5 for Windows. I have not touched any code yet - I'm starting with xbuild's recent ability to build sln files. (Incidentally I use Jenkins to trigger builds, not that it matters as I get the same result at the command-line.)
I get "error CS1548: Error during assembly signing. The specified key file `AlphaBeta.pfx' has incorrect format". There's not much google juice on this error. Does anyone know what would cause this? Thanks in advance!
Full output below:
C:\Program Files\Jenkins\jobs\AlphaBeta\...\AlphaSolution>"C:\Program Files\Mono-2.10.5\bin\xbuild" AlphaSolution.sln
XBuild Engine Version 2.10.5.0
Mono, Version 2.10.5.0
Copyright (C) Marek Sieradzki 2005-2008, Novell 2008-2011.
Build started 9/20/2011 3:54:14 PM.
C:\Program Files\Jenkins\jobs\AlphaBeta\...\AlphaSolution\AlphaSolution.sln: warning : Ignoring vcproj 'ZBM'.
C:\Program Files\Jenkins\jobs\AlphaBeta\...\AlphaSolution\AlphaSolution.sln: warning : Don't know how to handle GlobalSection TestCaseManagementSettings, Ignoring.
C:\Program Files\Jenkins\jobs\AlphaBeta\...\AlphaSolution\AlphaSolution.sln: warning : Failed to find project d393406d-3397-4907-a536-2a4b77512bc6
Project "C:\Program Files\Jenkins\jobs\AlphaBeta\...\AlphaSolution\AlphaSolution.sln" (default target(s)):
Target ValidateSolutionConfiguration:
Building solution configuration "Debug|Mixed Platforms".
Target Build:
Project "C:\Program Files\Jenkins\jobs\AlphaBeta\...\AlphaSolution\AlphaCommon\AlphaCommon.csproj" (default target(s)):
Target PrepareForBuild:
Configuration: Debug Platform: AnyCPU
Target GenerateSatelliteAssemblies:
No input files were specified for target GenerateSatelliteAssemblies, skipping.
Target CoreCompile:
Tool C:\PROGRA~1\MONO-2~1.5\bin\dmcs.bat execution started with arguments: /noconfig /debug:full /debug+ /keyfile:AlphaBeta.pfx /optimize- /out:obj\Debug\AlphaCommon.dll AlphaCommon.cs Properties\AssemblyInfo.cs /target:library /define:"DEBUG;TRACE" /reference:C:\PROGRA~1\MONO-2~1.5\lib\mono\xbuild-frameworks\.NETFramework\v4.0\RedistList\..\..\..\..\4.0\System.dll /reference:C:\PROGRA~1\MONO-2~1.5\lib\mono\xbuild-frameworks\.NETFramework\v4.0\RedistList\..\..\..\..\4.0\System.Xml.Linq.dll /reference:C:\PROGRA~1\MONO-2~1.5\lib\mono\xbuild-frameworks\.NETFramework\v4.0\RedistList\..\..\..\..\4.0\System.Data.DataSetExtensions.dll /reference:C:\PROGRA~1\MONO-2~1.5\lib\mono\xbuild-frameworks\.NETFramework\v4.0\RedistList\..\..\..\..\4.0\Microsoft.CSharp.dll /reference:C:\PROGRA~1\MONO-2~1.5\lib\mono\xbuild-frameworks\.NETFramework\v4.0\RedistList\..\..\..\..\4.0\System.Data.dll /reference:C:\PROGRA~1\MONO-2~1.5\lib\mono\xbuild-frameworks\.NETFramework\v4.0\RedistList\..\..\..\..\4.0\System.Xml.dll /reference:C:\PROGRA~1\MONO-2~1.5\lib\mono\xbuild-frameworks\.NETFramework\v4.0\RedistList\..\..\..\..\4.0\System.Core.dll /warn:4
: error CS1548: Error during assembly signing. The specified key file `AlphaBeta.pfx' has incorrect format
Task "Csc" execution -- FAILED
Done building target "CoreCompile" in project "C:\Program Files\Jenkins\jobs\AlphaBeta\...\AlphaSolution\AlphaCommon\AlphaCommon.csproj".-- FAILED
Mono does not support using PKCS#12 (.pfx) files to store keys used for strongnaming assemblies. This is a known issue and tracked on Xamarin's bugzilla #725.
A workaround is to export your key into a .snk file and use this when building your project.
The answers here provide examples of how to generate an .snk from a .pfx.

Categories

Resources