LS2013 Core Project – PowerShell script to create new app

Here is a PowerShell script, as requested, that will copy your LsCoreProject to a location on your drive and change the name to your choosing. Since LightSwitch doesn’t have an easy way to create a template, this is a pretty good alternative.

Edit the script for your project locations, run the script, wait for the Done dialog, open the new project in Visual Studio 2013, Set the startup project, Set the SecurityAdministration as enabled during debug and you are good to go!!

# =================================================================
# Script to copy and rename a LsCoreProject file
# Should also work for any other LS Project with a few minor edits
# =================================================================

# Source solution location
$sourceLocation = "c:\temp\LsCoreProject-master\LsCoreProject"

# Target solution location
$targetLocation = 'c:\Users\Dale\Documents\Visual Studio 2013\Projects\LsCore'

# What is the original solution name
$origSolutionName = "LsCoreProject"

# What is the new solution name
$newSolutionName = Read-Host -Prompt "New Solution Name?"
$newSolutionFolder = $targetLocation + "\" + $newSolutionName

# Copy the Source to the Target folder
Copy-Item $sourceLocation $newSolutionFolder -Recurse

# Make sure we don't move forward until the folder has been created
while (!(Test-Path $newSolutionFolder))
     Start-Sleep -s 1

# Change to the target location
cd $newSolutionFolder

# Get all the files that match our orig solution name
$files = Get-ChildItem $(get-location) -filter *$origSolutionName* -Recurse

# Change the folder and filenames to the new solution name
$files |
    Sort-Object -Descending -Property { $_.FullName } |
    Rename-Item -newname { $ -replace $origSolutionName, $newSolutionName } -force

# Get all the files that has our original name in its body
$files = Get-ChildItem -recurse | Select-String -pattern $origSolutionName | group path | select name

# Loop over all the matching files, replace original with new
foreach($file in $files) 
	# Replace all the name occurances, save back to original file
	((Get-Content $file.Name) -creplace $origSolutionName, $newSolutionName) | set-content $file.Name 

# Acknowledge to the user that we're done
read-host -prompt "Done! Press any key to close."

Couple of things, make sure your file is unblocked before unzipping, edit the script for your source and target locations.

I’ll also post the script file on github.

Updates are also coming to the LsCoreProject.


3 thoughts on “LS2013 Core Project – PowerShell script to create new app

  1. […] LS2013 核心工程 – PowerShell脚本创建新的应用程序 […]

  2. Having gone through the detailed and slightly painful process manually I thought to myself that I must look at creating a PS script. Boom! I’m loving your work mate🙂

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: