Giter Club home page Giter Club logo

Comments (11)

TedMobile avatar TedMobile commented on June 29, 2024 4

Is there a tutorial that takes you through how to create a solution template step by step? thanks

from dotnet-template-samples.

joeaudette avatar joeaudette commented on June 29, 2024 2

I managed to get my project template to create the folder structure I want and a .sln file ie:

|-src

|-WebApp

|-WebApp.csproj
WebApp.sln

It works as I wish using dotnet new, but I use the same template in vsix with sidewaffle and I end up with 2 .sln files and a folder structure nested one level deeper than I want, ie I get:

|-WebApp

|-src

|-WebApp
|-WebApp.csproj
|-WebApp.sln
WebApp.sln

I know this is a little off topic since not directly an issue with dotnet new template, but hoping someone here might have some tips. I would like to prevent VS/vsix/sidewaffle from creating a .sln file and instead use the one already included in the template. If anyone here knows how to do that I would greatly appreciate the help.

from dotnet-template-samples.

sayedihashimi avatar sayedihashimi commented on June 29, 2024

@seancpeters can you post a sample .sln file which has a conditional project entry?

from dotnet-template-samples.

seancpeters avatar seancpeters commented on June 29, 2024

At this point, to create conditions in a solution file so that the .sln file remains syntactically correct requires setting up a custom operation configuration in the template.json file. But this PR dotnet/templating#979 will provide better built in support for .sln files. Once this is merged, it'll become easier.

Current Situation
This section explains how to setup conditions in .sln files which will work right now. Note that this will remain backwards compatible after the PR, but it's a bit more complicated and syntactically different.

A custom conditional setup must be configured in the template.json, the following can be copied as-is:

  "SpecialCustomOperations": {
    "*.sln" : {
      "Operations": [
        {
          "type": "conditional",
          "configuration": {
            "style": "line",
            "token": "#"
          }
        }
      ]
    }
  },

The key “SpecialCustomOperations” is a top-level key, and so should appear at the same level as things such as “identity” & “tags”.

This configuration defines the syntax of conditional operations in “*.sln” files. The style is “line” to indicate we’re defining line-comments (as opposed to block comments, such as “” comments). The token value of “#” indicates what the conditional keywords will be preceded with. Template engine conditional operations come in two styles, “regular” and ”actionable”. Both styles operate in the same manner in terms of being conditional. The difference is that the “actionable” ones get a comment stripped from each line of their content if the content is emitted (this is the same as the built-in conditional operations). The format of the operations will be:

  • Regular:
    o ##if
    o ##elseif, ##elif
    o ##else
    o ##endif
  • Actionable:
    o ###if
    o ###elseif, ###elif
    o ###else

With this configuration, a .sln file can be conditioned similarly to any other file in a template. The following demonstrates optionally including various projects in a solution:

###if (CreateSharedProject)
#Project("{0828A3AA-EEE2-47CD-A744-86FE389AFD95}") = "BlankApp", "BlankApp\BlankApp.shproj", "{222CF9AB-CAD6-4608-BE59-DE5D3ECDC464}"
#EndProject
###else
#Project("{222CF9AB-CAD6-4608-BE59-DE5D3ECDC464}") = "BlankApp", "BlankApp\BlankApp.csproj", "{1C9BC7AB-9807-4F5E-9B07-4E82B2571A3B}"
#EndProject
##endif

##if (CreateiOSProject)
Project("{222CF9AB-CAD6-4608-BE59-DE5D3ECDC464}") = "BlankApp.iOS", "iOS\BlankApp.iOS.csproj", "{DBB686D5-B2FB-45C9-9A7F-62522D96764A}"
EndProject
##endif

###if (CreateAndroidProject)
#Project("{222CF9AB-CAD6-4608-BE59-DE5D3ECDC464}") = "BlankApp.Android", "Android\BlankApp.Android.csproj", "{4E5F77BC-F200-4335-8663-16006DC548EC}"
#EndProject
##endif

###if (CreateUWPProject)
#Project("{222CF9AB-CAD6-4608-BE59-DE5D3ECDC464}") = "BlankApp.UWP", "UWP\BlankApp.UWP.csproj", "{512666F3-34A0-46F7-A869-AD681CC33A9F}"
#EndProject
##endif

Near Future
PR dotnet/templating#979 provides built in support for conditionals in .sln files. Thus, there is no need to setup a custom configuration in template.json files. The syntax of the conditional operations will be slightly different than using the custom configuration, they will be:

  • Regular:
    o #if
    o #elseif, #elif
    o #else
    o #endif
  • Actionable:
    o ##if
    o ##elseif, ##elif
    o ##else
    The difference from the custom config setup is that each of these has one fewer '#' symbols. Thus, using them in a .sln file is very similar to the above:
##if (CreateSharedProject)
#Project("{0828A3AA-EEE2-47CD-A744-86FE389AFD95}") = "BlankApp", "BlankApp\BlankApp.shproj", "{222CF9AB-CAD6-4608-BE59-DE5D3ECDC464}"
#EndProject
##else
#Project("{222CF9AB-CAD6-4608-BE59-DE5D3ECDC464}") = "BlankApp", "BlankApp\BlankApp.csproj", "{1C9BC7AB-9807-4F5E-9B07-4E82B2571A3B}"
#EndProject
#endif

#if (CreateiOSProject)
Project("{222CF9AB-CAD6-4608-BE59-DE5D3ECDC464}") = "BlankApp.iOS", "iOS\BlankApp.iOS.csproj", "{DBB686D5-B2FB-45C9-9A7F-62522D96764A}"
EndProject
#endif

##if (CreateAndroidProject)
#Project("{222CF9AB-CAD6-4608-BE59-DE5D3ECDC464}") = "BlankApp.Android", "Android\BlankApp.Android.csproj", "{4E5F77BC-F200-4335-8663-16006DC548EC}"
#EndProject
#endif

##if (CreateUWPProject)
#Project("{222CF9AB-CAD6-4608-BE59-DE5D3ECDC464}") = "BlankApp.UWP", "UWP\BlankApp.UWP.csproj", "{512666F3-34A0-46F7-A869-AD681CC33A9F}"
#EndProject
#endif

from dotnet-template-samples.

a-patel avatar a-patel commented on June 29, 2024

any update?

from dotnet-template-samples.

seancpeters avatar seancpeters commented on June 29, 2024

@a-patel The "Near Future" scenario from my previous post has been merged, and is available in 2.1.0-preview1 or newer builds. The syntax for .sln file comments shown in the above post is built in, and doesn't need to be configured in template.json

from dotnet-template-samples.

a-patel avatar a-patel commented on June 29, 2024

Can I create the 'Multi project with solution file' (ASP.Net Core 2.0) using SidewaffleCreator2017

from dotnet-template-samples.

a-patel avatar a-patel commented on June 29, 2024

My Directory structure is like:

|- data
|-design
|-help
|-src
>|-.sln (VS solution file)
>|-Libraries
>>|-LIB1.csproj
>>|-LIB2.csproj
>>|-LIB3.csproj

|-Presentation
>>|-PRE1.csproj
>>|-PRE2.csproj
>|-Tests
>>|-TEST1.csproj
>>|-TEST2.csproj
>|-Plugins
>>|-Plugin1.csproj
>>|-Plugin2.csproj

from dotnet-template-samples.

sayedihashimi avatar sayedihashimi commented on June 29, 2024

Yes it should work. Let us know if you run into any issues.

from dotnet-template-samples.

sayedihashimi avatar sayedihashimi commented on June 29, 2024

Is there a tutorial that takes you through how to create a solution template step by step? thanks

Not that I'm aware of.

cc @KathleenDollard

from dotnet-template-samples.

orendin avatar orendin commented on June 29, 2024

Hi all

We're basically trying to build a Service Template solution for .net core "micro" services.
I have tried your suggested approach in the sln file with the conditionals and it works ok when the template is executed. The two files in the if-block get excluded in the final sln file.

However, ideally we would want to open the solution to continue to refine our service template over time. But every time we make a change resulting in changes to the solution file, once we save using Visual Studio (currently 15.9.3), it will remove the if-tags. We usually notice and revert the changes before commit, but it's somewhat of a hassle.

Is there a work-around for this or are we not using it correctly? I have also tried with double-#, but it doesn't affect the outcome.

Example:

Project("{fb8acff2-d9c2-4af7-bb7c-3adb281d1acb}") = "Solution Items", "Solution Items", "{282809d3-ba53-4273-ad3e-0ab728be1389}"

	ProjectSection(SolutionItems) = preProject
		.gitignore = .gitignore
		artifact-ci.yml = artifact-ci.yml
		Nuget.config = Nuget.config
#if (includeTemplateConfig)
		.template.config\template.json = .template.config\template.json
		readme.template.md = readme.template.md
#endif 
		StyleCop.ruleset = StyleCop.ruleset
	EndProjectSection

EndProject

from dotnet-template-samples.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.