Skip to content

Commit

Permalink
fixed bugs with paths and refactored the solution init script
Browse files Browse the repository at this point in the history
  • Loading branch information
TomProkop committed Jun 12, 2024
1 parent 5333e44 commit d3a09ca
Show file tree
Hide file tree
Showing 23 changed files with 93 additions and 48 deletions.
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ dotnet new install TALXIS.DevKit.Templates.Dataverse
### Solutions
Initialize a new empty solution:
```console
dotnet new pp-solution --SolutionDisplayName "Solutions.Presentation" --PublisherName "tomas" --PublisherPrefix "tom" --allow-scripts yes
dotnet new pp-solution `
--output "src/Solutions.Model" `
--PublisherName "tomas" `
--PublisherPrefix "tom" `
--allow-scripts yes
```

### Tables
Expand All @@ -38,39 +42,43 @@ dotnet new pp-entity `
--LogicalNamePlural "locations" `
--DisplayName "Location" `
--DisplayNamePlural "Locations" `
--SolutionRootPath "Declarations" `
--allow-scripts yes
```

Create a new *activity* table:
```console
dotnet new pp-entity `
--EntityType Activity `
--Behavior New `
--EntityType "Activity" `
--Behavior "New" `
--PublisherPrefix "tom" `
--LogicalName "shiftevent" `
--LogicalNamePlural "shiftevents" `
--DisplayName "Shift Event" `
--DisplayNamePlural "Shift Events" `
--SolutionRootPath "Declarations" `
--allow-scripts yes
```

Add an existing *custom table* to a solution:
```console
dotnet new pp-entity `
--Behavior Existing `
--Behavior "Existing" `
--PublisherPrefix "tom" `
--LogicalName "shiftevent" `
--DisplayName "Shift Event" `
--SolutionRootPath "Declarations" `
--allow-scripts yes
```

Add an existing *system table* to a solution:
```console
dotnet new pp-entity `
--Behavior Existing `
--IsSystemEntity true `
--Behavior "Existing" `
--IsSystemEntity "true" `
--LogicalName "account" `
--DisplayName "Account" `
--SolutionRootPath "Declarations" `
--allow-scripts yes
```

Expand Down
1 change: 1 addition & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Implement exception handling in template scripts - currently it doesn't even tell you that it couldn't find solution.xml file
36 changes: 22 additions & 14 deletions src/Dataverse/templates/pp-entity/.template.config/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,55 +15,63 @@
{
"condition": "(Behavior == \"New\")",
"exclude": [
"examplepublisherprefix_examplecustomentity/SavedQueries/{customViewId}.xml"
"SolutionDeclarationsRoot/Entities/examplepublisherprefix_examplecustomentity/SavedQueries/{customViewId}.xml"
]
},
{
"condition": "(Behavior == \"Existing\")",
"exclude": [
"examplepublisherprefix_examplecustomentity/SavedQueries/{defaultViewId}.xml",
"examplepublisherprefix_examplecustomentity/SavedQueries/{quickFindViewId}.xml",
"examplepublisherprefix_examplecustomentity/SavedQueries/{myRecordsViewId}.xml",
"examplepublisherprefix_examplecustomentity/SavedQueries/{lookupViewId}.xml",
"examplepublisherprefix_examplecustomentity/SavedQueries/{advancedFindViewId}.xml",
"examplepublisherprefix_examplecustomentity/SavedQueries/{associatedViewId}.xml"
"SolutionDeclarationsRoot/Entities/examplepublisherprefix_examplecustomentity/SavedQueries/{defaultViewId}.xml",
"SolutionDeclarationsRoot/Entities/examplepublisherprefix_examplecustomentity/SavedQueries/{quickFindViewId}.xml",
"SolutionDeclarationsRoot/Entities/examplepublisherprefix_examplecustomentity/SavedQueries/{myRecordsViewId}.xml",
"SolutionDeclarationsRoot/Entities/examplepublisherprefix_examplecustomentity/SavedQueries/{lookupViewId}.xml",
"SolutionDeclarationsRoot/Entities/examplepublisherprefix_examplecustomentity/SavedQueries/{advancedFindViewId}.xml",
"SolutionDeclarationsRoot/Entities/examplepublisherprefix_examplecustomentity/SavedQueries/{associatedViewId}.xml"
]
},
{
"condition": "(!AddMainForm)",
"exclude": [
"examplepublisherprefix_examplecustomentity/FormXml/main/*"
"SolutionDeclarationsRoot/Entities/examplepublisherprefix_examplecustomentity/FormXml/main/*"
]
},
{
"condition": "(!AddQuickForm)",
"exclude": [
"examplepublisherprefix_examplecustomentity/FormXml/quick/*"
"SolutionDeclarationsRoot/Entities/examplepublisherprefix_examplecustomentity/FormXml/quick/*"
]
},
{
"condition": "(!AddCardForm)",
"exclude": [
"examplepublisherprefix_examplecustomentity/FormXml/card/*"
"SolutionDeclarationsRoot/Entities/examplepublisherprefix_examplecustomentity/FormXml/card/*"
]
},
{
"condition": "(!AddQuickCreateForm)",
"exclude": [
"examplepublisherprefix_examplecustomentity/FormXml/quickCreate/*"
"SolutionDeclarationsRoot/Entities/examplepublisherprefix_examplecustomentity/FormXml/quickCreate/*"
]
},
{
"condition": "(!AddCustomView)",
"exclude": [
"examplepublisherprefix_examplecustomentity/SavedQueries/{customViewId}.xml"
"SolutionDeclarationsRoot/Entities/examplepublisherprefix_examplecustomentity/SavedQueries/{customViewId}.xml"
]
}
]
}
],
"preferNameDirectory": false,
"symbols": {
//this was supposed to be done using msbuild props binding but it didn't work for some reason
"SolutionRootPath": {
"type": "parameter",
"datatype": "text",
"defaultValue": ".",
"replaces": "SolutionDeclarationsRoot",
"fileRename": "SolutionDeclarationsRoot"
},
"IsSystemEntity": {
"type": "parameter",
"datatype": "bool",
Expand Down Expand Up @@ -138,9 +146,9 @@
}
]
},
"replaces":"examplepublisherprefix_",
"replaces": "examplepublisherprefix_",
"fileRename": "examplepublisherprefix_"
},
},
"PublisherPrefix": {
"type": "parameter",
"datatype": "text",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Resolve the relative path to an absolute path (to support other OSes)
$solutionPath = Resolve-Path -Path '../Other/Solution.xml'
$solutionPath = Resolve-Path -Path 'SolutionDeclarationsRoot/Other/Solution.xml'

# Load the XML file
[XML]$File = Get-Content -Path $solutionPath -Raw
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Resolve the relative path to an absolute path (to support other OSes)
$solutionPath = Resolve-Path -Path '../Other/Solution.xml'
$solutionPath = Resolve-Path -Path 'SolutionDeclarationsRoot/Other/Solution.xml'

# Load the XML file
[XML]$File = Get-Content -Path $solutionPath -Raw
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Resolve the relative path to an absolute path (to support other OSes)
$solutionPath = Resolve-Path -Path '../Other/Solution.xml'
$solutionPath = Resolve-Path -Path 'SolutionDeclarationsRoot/Other/Solution.xml'

# Load the XML file
[XML]$File = Get-Content -Path $solutionPath -Raw
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Resolve the relative path to an absolute path (to support other OSes)
$solutionPath = Resolve-Path -Path '../Other/Solution.xml'
$solutionPath = Resolve-Path -Path 'SolutionDeclarationsRoot/Other/Solution.xml'

# Load the XML file
[XML]$File = Get-Content -Path $solutionPath -Raw
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Resolve the relative path to an absolute path (to support other OSes)
$solutionPath = Resolve-Path -Path '../Other/Solution.xml'
$solutionPath = Resolve-Path -Path 'SolutionDeclarationsRoot/Other/Solution.xml'

# Load the XML file
[XML]$File = Get-Content -Path $solutionPath -Raw
Expand Down
15 changes: 3 additions & 12 deletions src/Dataverse/templates/pp-solution/.template.config/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"language": "C#",
"type": "project"
},
"sourceName": "Solutions.Example",
"sourceName": "SolutionLogicalNameExample",
"sources": [
{
"exclude": [
Expand All @@ -22,17 +22,8 @@
]
}
],
"preferNameDirectory": false,
"preferNameDirectory": true,
"symbols": {
"SolutionDisplayName": {
"type": "parameter",
"datatype": "text",
"displayName": "Solution Display Name",
"description": "Specify a solution name",
"replaces": "Solutions.Example",
"fileRename": "Solutions.Example",
"isRequired": true
},
"PublisherName": {
"type": "parameter",
"datatype": "text",
Expand All @@ -47,7 +38,7 @@
},
"primaryOutputs": [
{
"path": "Solutions.Example/Solutions.Example.cdsproj"
"path": "SolutionLogicalNameExample.cdsproj"
}
],
"postActions": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,54 @@
# Initialize a Dataverse solution project
pac solution init --publisher-name examplepublisher --publisher-prefix examplepublisherprefix --outputDirectory Solutions.Example
cd Solutions.Example
# Initialize a Dataverse solution project using PAC CLI
pac solution init --publisher-name examplepublisher --publisher-prefix examplepublisherprefix --outputDirectory "SolutionLogicalNameExample"
cd "SolutionLogicalNameExample"

# Rename the src folder (produced by PAC CLI to remove the double src folder)
# and remove the unnecessary .gitignore file (we already have one in the root)
# and remove the unnecessary .gitignore file (we already have one in the repository root)
Rename-Item -Path .\src -NewName Declarations && Remove-Item .gitignore -Force

# Rename the solution component folder in .cdsproj and add the missing project type ID to make dotnet accept the custom project type
$csproj = Get-ChildItem -Path . -Filter *.cdsproj | Select-Object -First 1; [xml]$xml = Get-Content $csproj.FullName -Raw; $propertyGroup = $xml.Project.PropertyGroup | Where-Object { $_.SolutionRootPath } | Select-Object -First 1; $propertyGroup.SolutionRootPath = 'Declarations'; $newElement = $xml.CreateElement('DefaultProjectTypeGuid', $xml.Project.NamespaceURI); $newElement.InnerText = 'FAE04EC0-301F-11D3-BF4B-00C04F79EFBC'; $propertyGroup.AppendChild($newElement) > $null; $xml.Save($csproj.FullName)
# Find the .cdsproj file and read it as XML
$csproj = Get-ChildItem -Path . -Filter *.cdsproj | Select-Object -First 1
[xml]$xml = Get-Content $csproj.FullName -Raw

# Switch solution ty to both
# sanitize UniqueName element value to remove characters other than letters and numbers
# by finding the first Solution.xml in subfolders, then reading the xml, them readint element value of ImportExportXml/SolutionManifest/UniqueName and then updating it with the sanitized value
$solutionXml = Get-ChildItem -Path . -Filter Solution.xml -Recurse | Select-Object -First 1; [xml]$xml = Get-Content $solutionXml.FullName -Raw; $uniqueName = $xml.ImportExportXml.SolutionManifest.UniqueName; $sanitized = [regex]::Replace($uniqueName, '[^a-zA-Z0-9]', ''); $xml.ImportExportXml.SolutionManifest.UniqueName = $sanitized; $xml.ImportExportXml.SolutionManifest.Managed = 2; $xml.Save($solutionXml.FullName)
# Rename the solution component folder in .cdsproj and
$propertyGroup = $xml.Project.PropertyGroup | Where-Object { $_.SolutionRootPath } | Select-Object -First 1
$propertyGroup.SolutionRootPath = 'Declarations'

cd ..
# Add the missing project type ID to make dotnet accept the custom project type
$newElement = $xml.CreateElement('DefaultProjectTypeGuid', $xml.Project.NamespaceURI)
$newElement.InnerText = 'FAE04EC0-301F-11D3-BF4B-00C04F79EFBC'
$propertyGroup.AppendChild($newElement) > $null

# Override the default Publish target to prevent errors when running publish on .sln file
$targetElement = $xml.CreateElement('Target', $xml.Project.NamespaceURI)
$targetElement.SetAttribute('Name', 'Publish')
$comment = $xml.CreateComment(' Override the default Publish target to prevent errors when running publish on .sln file ')
$xml.Project.AppendChild($comment) > $null
$xml.Project.AppendChild($targetElement) > $null

# Save the updated XML back to the .cdsproj file
$xml.Save($csproj.FullName)

# Find the Solution.xml file and read it as XML
$solutionXml = Get-ChildItem -Path . -Filter Solution.xml -Recurse | Select-Object -First 1
[xml]$xml = Get-Content $solutionXml.FullName -Raw

# Find the UniqueName element and sanitize it
$uniqueName = $xml.ImportExportXml.SolutionManifest.UniqueName
$sanitized = [regex]::Replace($uniqueName, '[^a-zA-Z0-9]', '')
$xml.ImportExportXml.SolutionManifest.UniqueName = $sanitized

# Switch solution type to both to support packing managed solutions using SolutionPackager
$xml.ImportExportXml.SolutionManifest.Managed = 2

# Save the updated XML back to the file
$xml.Save($solutionXml.FullName)

cd ..

# Move the solution files from the temp folder to the root
Move-Item -Path "SolutionLogicalNameExample\*" -Destination . -Force
Remove-Item -Path "SolutionLogicalNameExample" -Force

# The new project is automatically added to the Visual Studio solution by the templating engine
# This would be an alternative: dotnet sln ../../ add SolutionLogicalNameExample.cdsproj"

0 comments on commit d3a09ca

Please sign in to comment.