在asp.net核心中以编程方式更改解决方案名称的最佳方法是什么?

时间:2017-07-18 19:03:43

标签: c# asp.net-mvc powershell visual-studio-2015 setup-project

我正在寻找一种方法来为ASP.NET Core Projects提供不断变化的解决方案/项目名称功能。我的第一个想法是在安装程序功能中以编程方式执行此操作,开发人员将编写项目名称。是可以在.NET Framework中还是通过Powershell?

谢谢!

1 个答案:

答案 0 :(得分:0)

您可以使用以下功能帮助您更改:

以下是参考链接:

1)Link 1

2)Link 2

function Rename-Project
{
# designed to run from the src folder
param(
    [string]$projectName=$(throw "projectName required."),
    [string]$newProjectName=$(throw "newProjectName required.")
)

if(!(Test-Path $projectName)){
    Write-Error "No project folder '$projectName' found"
    return
}

if(!(Test-Path $projectName\$projectName.csproj)){
    Write-Error "No project '$projectName\$projectName.dll' found"
    return
}

if((Test-Path $newProjectName)){
    Write-Error "Project '$newProjectName' already exists"
    return
}

# project
hg rename $projectName\$projectName.csproj $projectName\$newProjectName.csproj

# folder
hg rename $projectName $newProjectName

# assembly title
$assemblyInfoPath = "$newProjectName\Properties\AssemblyInfo.cs"
(gc $assemblyInfoPath) -replace """$projectName""","""$newProjectName""" | sc $assemblyInfoPath

# root namespace
$projectFile = "$newProjectName\$newProjectName.csproj"
(gc $projectFile) -replace "<RootNamespace>$projectName</RootNamespace>","<RootNamespace>$newProjectName</RootNamespace>" | sc $projectFile

# assembly name
(gc $projectFile) -replace "<AssemblyName>$projectName</AssemblyName>","<AssemblyName>$newProjectName</AssemblyName>" | sc $projectFile

# other project references
gci -Recurse -Include *.csproj |% { (gc $_) -replace "..\\$projectName\\$projectName.csproj", "..\$newProjectName\$newProjectName.csproj" | sc $_ }
gci -Recurse -Include *.csproj |% { (gc $_) -replace "<Name>$projectName</Name>", "<Name>$newProjectName</Name>" | sc $_ }

# solution 
gci -Recurse -Include *.sln |% { (gc $_) -replace "\""$projectName\""", """$newProjectName""" | sc $_ }
gci -Recurse -Include *.sln |% { (gc $_) -replace "\""$projectName\\$projectName.csproj\""", """$newProjectName\$newProjectName.csproj""" | sc $_ }
}