【发布时间】:2020-01-18 22:06:37
【问题描述】:
在使用 npm i -g azure-functions-core-tools@3 --unsafe-perm true 安装 Azure Functions Core Tools 后,我假设 func init --ProjectName 命令将使用 AzureFunctionsVersion v3 创建 Azure Functions 项目,但它在项目文件中使用 v2 创建:
.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<AzureFunctionsVersion>v2</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.1" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
设置环境变量CLI_DEBUG=1后重新运行我实现的func init命令,会触发如下命令:
> dotnet new --install "C:\Users\murat\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\templates\itemTemplates.3.0.10405.nupkg"
> dotnet new --install "C:\Users\murat\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\templates\projectTemplates.3.0.10405.nupkg"
> dotnet new func --AzureFunctionsVersion v2 --name ProjectName --StorageConnectionStringValue "UseDevelopmentStorage=true"
> dotnet new --uninstall "C:\Users\murat\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\templates\itemTemplates.3.0.10405.nupkg"
> dotnet new --uninstall "C:\Users\murat\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\templates\projectTemplates.3.0.10405.nupkg"
显然它调用了--AzureFunctionsVersion v2 参数。
这是默认行为吗?
因为如果我在文件夹中使用 dotnet new func 命令,或者使用 VS2019 AzureFunctions v3 Project,它会将 AzureFunctionsVersion 设置为 v3
在挖掘 AcureFunctionsCoreTools 源代码后,我在 DotnetHelpers 类的 DeployDotnetProject 方法中发现了以下代码:
public async static Task DeployDotnetProject(string Name, bool force)
{
await TemplateOperation(async () =>
{
var connectionString = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
? $"--StorageConnectionStringValue \"{Constants.StorageEmulatorConnectionString}\""
: string.Empty;
var exe = new Executable("dotnet", $"new func --AzureFunctionsVersion v2 --name {Name} {connectionString} {(force ? "--force" : string.Empty)}");
var exitCode = await exe.RunAsync(o => { }, e => ColoredConsole.Error.WriteLine(ErrorColor(e)));
if (exitCode != 0)
{
throw new CliException("Error creating project template");
}
});
}
我们还需要这个--AzureFunctionsVersion v2 参数吗?
【问题讨论】:
标签: azure-functions azure-functions-core-tools