Creating new project with template not renaming to sourceName - .net-6.0

I've created a new Template for a .NET 6 project, and I'm trying to make sure it renames the project and solution file on creation. I have the following in my template.json file:
{
"$schema": "http://json.schemastore.org/template",
"author": "Jake Ford",
"classifications": [ "FordWareMVC", "FordWareMVC", "C#" ],
"identity": "FordWareTemplates.MVC",
"name": "FordWare MVC Template",
"shortName": "fordwaremvc",
"sourceName": "_fordwaremvc",
"tags": {
"language": "C#",
"type": "project"
}
}
and I am running the following command, using -n to set the source name and -o to set the folder directory for the new project:
dotnet new fordwaremvc -n NewProjectName -o NewProjectName
It creates the project, but the template/solution name is not "NewProjectName", it just uses the name of the original template project...
Am I doing something wrong with the sourceName?

Finally found the following:
sourceName: This is the value in your project/solution that will get replaced with the user-provided value in the -o parameter. Make sure this matches the name you chose when creating your template project / solution. The value above matches my project / solution name if you look at the template repo.
From here: https://knowyourtoolset.com/2021/08/creating-useful-net-templates/
The sourceName apparently needs to match the original solution/project name. I edited my template.json to this, and uninstalled/re-installed the template again and the original command worked:
{
"$schema": "http://json.schemastore.org/template",
"author": "Jake Ford",
"classifications": [ "FordWareMVC", "FordWareMVC", "C#" ],
"identity": "FordWareTemplates.MVC",
"name": "FordWare MVC Template",
"shortName": "fordwaremvc",
"sourceName": "FordWare_Template",
"tags": {
"language": "C#",
"type": "project"
}
}

Related

use visual studio templates to rename part of a class and file name

I want to be able to rename classes using dotnet new project templates like
these examples
I want to have files/classes that have the same name as the project with a suffix that automatically rename to match the project
eg [projectname]DbContext, ProjectNameDto so if my template is called MyWebTemplate and it has a class MyWebTempaleDbContext and the user picks a name Of MyWebApp the file and class would be renamed to MyWebAppDbContext.
I am able to do this with parameters, but want to do this for multiple classes and dont want to have to add a parameter for this
here is how it can be done with parameters :
"DBContextName": {
"type": "parameter",
"defaultValue": "WebApplicationDbContext",
"replaces": "WebApplicationDbContext",
"FileRename": "WebApplicationDbContext",
"datatype": "text",
"description": "Db Context Name"
},
Is there a way to do this using RegEx or regex match?
The example they give is :
"symbols": {
"regexExample": {
"type": "generated",
"generator": "regex",
"dataType": "string",
"replaces": "A different message", //The value to replace in the output
"parameters": {
"source": "message", //The name of the symbol whose value should be operated on
"steps": [
{
"regex": "^test", //The regular expression whose matches will be replaced with '[Replaced]`
"replacement": "[Replaced]" //The value to replace matches of the expression '^test' with
},
{
"regex": "test$",
"replacement": "[/Replaced]"
}
]
}
}
}
I also found a file rename example but cant seem to work out how to make the 2 do what i want:
{
...
"symbols": {
"app1Rename": {
"type": "derived",
"valueSource": "name",
"valueTransform": "ValueAfterLastDot",
"fileRename": "Application1",
"description": "A value derived from the 'name' param, used to rename Application1.cs"
}
}
...
"forms": {
"ValueAfterLastDot": {
"identifier": "replace",
"pattern": "^.*\\.(?=[^\\.]+$)", // regex to match everything up to and including the final "."
"replacement": "" // replace it with empty string
}
}
...
}
Thanks

SONARQUBE: how estract, via API, lines of code for each project

I've seen that I can found the line of code for a project on my SONAR instance using this command
http://<my_sonar_instance_url>/api/measures/component?componentKey=<project_name>&metricKeys=ncloc
and the output is
{
"component": {
"id": "<the_id>",
"key": "<the_key>",
"name": "<the_name>",
"qualifier": "TRK",
"measures": [
{
"metric": "ncloc",
"value": "37370"
}
]
}
}
That is fine!
Is there some way to extract the line of code of ALL my projects on SONAR "in bulk"? Or Do I've to cycle on my project list and extract them one to one?
Thank you in advance!

Microsoft Flow fails when trigger event is Create a File on OneDrive for Business

I am triggering a flow when a new file is added to a folder (/Flows/InvoicesToXero/) in OneDrive for business.
However, it sees to think that the folder is a file and this causes issues:
{
"status": 400,
"message": "The file id '/Flows/InvoicesToXero/' is not valid.",
"source": "api.connectorp.svc.ms"
}
This is probably the simplest flow you could have:
Full error here:
This is the json for the trigger: (I have tried with and without a trailing slash)
{
"inputs": {
"host": {
"connection": {
"name": "#parameters('$connections')['shared_onedriveforbusiness']['connectionId']"
}
},
"method": "get",
"path": "/datasets/default/triggers/batch/onnewfile",
"queries": {
"folderId": "/Flows/InvoicesToXero",
"maxFileCount": 10
},
"authentication": "#parameters('$authentication')"
},
"recurrence": {
"interval": 5,
"frequency": "Minute"
},
"metadata": {
"b!caGb33cRrkC_foNq9zd0FIdP_xtQDcZEmqyeYyKvO6dYQu456-3vQaC_VKHi8b5w.014XBLOOWVAVAWSVA2QNELELS5LQI3SOJN": "/Flows/InvoicesToXero",
"flowSystemMetadata": {
"swaggerOperationId": "OnNewFiles"
}
},
"splitOn": "#triggerBody()"
}
How can I trigger a flow when a new file is added to OneDrive for Business in a subfolder?
You can try to create another connector also named "When a file is created (properties only)", please refer to this tutorial and the screenshot below:
According to the screenshot above, we can see there are two triggers named "When a file is created (properties only)" and the second include sub folders.
Hope it would be helpful to your problem~

Azure IoT event subscription with ARM template

I am trying to deploy Azure IoT device connected event subscription to Azure storage queue using ARM template and PowerShell. I have used the following template for deploying this. Also, I have read a lot of articles on Microsoft. But could not find any solution. Please help me to figure it out.
"resources": [
{
"type": "Microsoft.EventGrid/eventSubscriptions",
"name": "DeviceConnected",
"location": "[resourceGroup().location]",
"apiVersion": "2018-01-01",
"dependsOn": [
"[resourceId('Microsoft.Devices/IotHubs', variables('iotHubName'))]"
],
"properties": {
"destination": {
"endpointType": "storagequeue",
"properties": {
"queueName":"device-connnection-state-queue",
"resourceId": "[resourceId('Microsoft.Storage/storageAccounts', variables('storageName'))]"
}
},
"filter": {
"includedEventTypes": [
"Microsoft.Devices.DeviceConnected"
]
}
}
}
],
The error is showing like
The error you're seeing is related to the dependsOn property you've specified.
From MS documentation
Resources that must be deployed before this resource is deployed. Resource Manager evaluates the dependencies between resources and deploys them in the correct order. When resources aren't dependent on each other, they're deployed in parallel. The value can be a comma-separated list of a resource names or resource unique identifiers. Only list resources that are deployed in this template. Resources that aren't defined in this template must already exist. Avoid adding unnecessary dependencies as they can slow your deployment and create circular dependencies. For guidance on setting dependencies, see Defining dependencies in Azure Resource Manager templates.
So a resource that is not defined in an ARM template cannot be used in a DependsOn property.
Here is the documentation related to event subscription creation:
Microsoft.EventGrid eventSubscriptions template reference
There are not so much samples on how to create event subscription but you can extract some part of the template from the Azure Portal:
Click + Event Subscription
Fill in the details
Click the Advanced Editor button link on the top right corner
It will show you some of the details you need to create your ARM Template
Here is how a sample ARM template can look likes:
"resources": [
{
"type": "Microsoft.Devices/IotHubs/providers/eventSubscriptions",
"apiVersion": "2019-01-01",
"name": "[concat(parameters('iotHubName'), '/Microsoft.EventGrid/', parameters('eventSubName'))]",
"location": "[resourceGroup().location]",
"properties": {
"topic": "[resourceId('Microsoft.Devices/IotHubs', parameters('iotHubName'))]",
"destination": {
"endpointType": "StorageQueue",
"properties": {
"resourceId": "[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))]",
"queueName": "[parameters('queueName')]"
}
},
"filter": {
"includedEventTypes": [
"Microsoft.Devices.DeviceConnected"
],
"advancedFilters": []
},
"labels": [],
"eventDeliverySchema": "EventGridSchema"
}
}
]

Jira Trigger plugin for Jenkins: Obtaining Value from issue object

I'm trying to set up some automation using Jenkins and Jira Trigger plugin for Jenkins. I've set up a web hook at Jira side which is able to invoke build on Jenkins as desired.
I've a trouble with obtaining value for a custom field from incoming Jira request.
I'm trying to use "Issue Attribute Path" feature and I've also referred to post (How to use the 'Issue attribute path' in the parameter mapping of jenkins-trigger-plugin)
Howevevr I'm still unable to get value for custom fields customfield_10010, customfield_10011. I've tried with mapping like fields.customfield_10010, fields.customfield_10010.value, fields.customfield_10010.0.value,customfield_10010.0.value and similar combinations. I'm able to get value for other standard fields as suggested in plugin help. ex: status.name, description etc.
I could not get any clue from Jira documentation site either.
Parts of incoming json data is below for easy reference.
"issue": {
"id": "1000x",
"self": "http://localhost:3080/rest/api/2/issue/10007",
"key": "ABC-2",
"fields": {
"issuetype": {
..
},
"parent": {
..
},
"components": [
],
"timespent": null,
"timeoriginalestimate": 28800,
"description": ".....",
"project": {
..
},
"customfield_10010": [
{
"self": "http://localhost:3080/rest/api/2/customFieldOption/10019",
"value": "ABC-Custom 1",
"id": "10019"
}
],
"fixVersions": [
],
"customfield_10011": [
{
"self": "http://localhost:3080/rest/api/2/customFieldOption/10021",
"value": "ABC-Custom 2",
"id": "10021"
}
],
.....
....
....
}
}
You can get the value of a custom field with the following syntax:
fields.find { it.id == "customfield_10010" }.value
I had the same problem and found this solution here:
https://issues.jenkins-ci.org/browse/JENKINS-13216

Resources