question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow sourceName to be used as source for casing generator

See original GitHub issue

I’m after a way to get the lowercase version of the main template name. The below template configuration produces the issue with the below csproj file. Maybe I’ve got invalid syntax or an something else isn’t correct. I can’t just specify the lowercase name as the -n command because I want to support a mixed case for that parameter (e.g. I want the user to specify FooDomain instead of foodomain because of naming conventions).

To repro, you can use the following template config:

{  
  "$schema": "http://json.schemastore.org/template",
  "author": "Blank",
  "classifications": [
    "Web",
    "WebAPI"
  ],
  "name": "Test",
  "identity": "Test.Casing",
  "shortName": "casing-test",
  "sourceName": "ApplicationName",
  "preferNameDirectory": true,
  "tags": {  
    "language": "C#"
  },
  "primaryOutputs": [
    {  
      "path": "ApplicationName.csproj"
    }
  ],
  "symbols": {
    "sourceNameLower": {
      "type": "generated",
      "generator": "casing",
      "parameters": {
        "source":"sourceName",
        "toLower": true
      },
      "replaces": "ApplicationNameLower"
    }
  },
  "postActions": []
}

And a single file in the template content called “ApplicationName.csproj”:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.2</TargetFramework>
    <Authors>Blank/Authors>
    <Version>1.0.0</Version>
    <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
    <UserSecretsId>dd663411-3e30-405b-85b6-be2f9b61bf95</UserSecretsId>
    <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
    <ArtifactsDirectory>app</ArtifactsDirectory>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.7.9" />
  </ItemGroup>

    <!--
        DeleteArtifacts target:
            This target runs after clean.
    -->
    <Target Name="DeleteArtifacts" BeforeTargets="Package" Condition="Exists('$(ArtifactsDirectory)')">
        <Message Importance="High" Text="Deleting artifacts directory '$(ArtifactsDirectory)''" />
        <RemoveDir Directories="$(ArtifactsDirectory)" />
    </Target>
  
    <!--
        Package target:
            This target compiles the project in release mode and builds the docker container.
    -->
    <Target Name="Package">
        <Message Importance="High" Text="Publishing release artifacts..." />
        <Exec Command="dotnet publish -c Release -o $(ArtifactsDirectory)" />

        <Message Importance="High" Text="Building docker container..." />
        <Exec Command="docker build . -t ApplicationNameLower:latest" />
    </Target>

</Project>

My expectation is that when a user runs dotnet new casing-test -n FooDomain that they get a csproj called FooDomain.csproj with the Exec step in the Package target matching <Exec Command="docker build . -t foodomain:latest" />. Currently, the part that says foodomain is just left blank.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:19 (6 by maintainers)

github_iconTop GitHub Comments

9reactions
vlada-shubinacommented, Sep 15, 2020

@ardove sourceName is available in name symbol. The following change is needed to template.json:

{  
  "$schema": "http://json.schemastore.org/template",
  "author": "Blank",
  "classifications": [
    "Web",
    "WebAPI"
  ],
  "name": "Test",
  "identity": "Test.Casing",
  "shortName": "casing-test",
  "sourceName": "ApplicationName",
  "preferNameDirectory": true,
  "tags": {  
    "language": "C#"
  },
  "primaryOutputs": [
    {  
      "path": "ApplicationName.csproj"
    }
  ],
  "symbols": {
    "sourceNameLower": {
      "type": "generated",
      "generator": "casing",
      "parameters": {
        "source":"name",
        "toLower": true
      },
      "replaces": "ApplicationNameLower"
    }
  },
  "postActions": []
}
7reactions
RehanSaeedcommented, Jul 28, 2020

Any workarounds or news of a fix for this? I’d really like the lower case sourceName, so I can use it for a Docker tag which is required to be lower case.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Available Symbols Generators · dotnet/templating Wiki
Parameters ; source, string, The name of symbol to use as the source of data. yes ; toLower, bool, applies lower case if...
Read more >
dotnet cli - How to get camel case version of project name ...
Pull request #1723 introduced a(n as-yet undocumented) join generator. With this, and the also-undocumented derived symbols, ...
Read more >
Source Generators
Source Generators is a C# compiler feature that lets C# developers inspect user code as it is being compiled. Source generators create new ......
Read more >
TestCaseSource
TestCaseSource. TestCaseSourceAttribute is used on a parameterized test method to identify the source from which the required arguments will be provided.
Read more >
How to create your own templates for dotnet new - .NET Blog
Let's dive into the demos, and see how to create some templates. Everything that we cover here is in a GitHub repository at ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found