Reputation: 1143
I have created a project Template for MS Orleans Grain (.NET Standard 2.0 project) To install using this command:
dotnet new -i OrleansGrain.NetCore.ProjectTemplate::*
The package is hosted on Nuget.org, with .NET Console App I managed to make it work, but this package is .NET Standard 2.0 Class Library and when I try to install i got the following error message:
C:\Users\thiag.templateengine\dotnetcli\v2.1.403\scratch\restore.csproj : error NU1202: Package OrleansGrain.NetCore.ProjectTemplate 1.0.2 is not compatible with netcoreapp1.0 (.NETCoreApp,Version=v1.0). Package OrleansGrain.NetCore.ProjectTemplate 1.0.2 supports: netstandard2.0 (.NETStandard,Version=v2.0) Generating MSBuild file C:\Users\thiag.templateengine\dotnetcli\v2.1.403\scratch\obj\restore.csproj.nuget.g.props. Generating MSBuild file C:\Users\thiag.templateengine\dotnetcli\v2.1.403\scratch\obj\restore.csproj.nuget.g.targets. Restore failed in 1.73 sec for C:\Users\thiag.templateengine\dotnetcli\v2.1.403\scratch\restore.csproj.
Upvotes: 1
Views: 1202
Reputation: 94
Actually, there IS a way of making this work with the SDK style projects.
Via https://learn.microsoft.com/en-us/nuget/reference/msbuild-targets#suppress-dependencies, there's a SuppressDependenciesWhenPacking
property when added and set to true
in the .csproj file will skip adding the <dependencies>
node to the generated .nuspec file.
Here's an example of a PropertyGroup that will generate a proper dotnet template package.
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Description>SDK Style Test Template</Description>
<PackageType>Template</PackageType>
<PackageId>SDKStyle.DotNetTemplate.Test</PackageId>
<Product>SDKStyle.DotNetTemplate.Test</Product>
<Version>1.0</Version>
<Authors>SDKStyle.DotNetTemplate.Test</Authors>
<Company>SDKStyle.DotNetTemplate.Test</Company>
<SuppressDependenciesWhenPacking>true</SuppressDependenciesWhenPacking>
</PropertyGroup>
Upvotes: 0
Reputation: 1143
Found the issue, when creating a Nuget Package for Project Template we should use Nuget command line.
https://learn.microsoft.com/en-us/nuget/tools/cli-ref-pack
Need to create nuspec file and use:
nuget pack file.nuspec
Then the nupkg is generated correctly, instead from solution on Visual Studio.
Upvotes: 1