gpt4 book ai didi

c# - 如何让 BIML 编译器允许脚本任务、脚本组件中的 c#6 语言功能

转载 作者:太空宇宙 更新时间:2023-11-03 11:57:54 25 4
gpt4 key购买 nike

期望的结果:让我的 BimlStudio 项目输出一个 SSIS 包,其脚本任务(或脚本组件)使用 C# 6 语言功能。

我有一个 SSIS 2014 项目,其中包含一个已导入 BimlStudio 的包

Varigence BimlStudio 5.0 (64-bit)Build 5.0.63501.0

Visual Studio 版本信息:

Microsoft Visual Studio Professional 2017 Version 15.9.5VisualStudio.15.Release/15.9.5+28307.280Microsoft .NET FrameworkVersion 4.7.03056Microsoft Visual Studio Tools for Applications 2017   00370-20004-06228-AA500

我正要尝试编译我的 BimlStudio 项目。不是我必须这样做,而是因为我试图反射(reflect)我的原生 SSIS 2014 项目的构建行为,所以我更改了 .mst 文件中的默认 64 位 MSBuild 路径,从

C:\WINDOWS\Microsoft.NET\Framework64\v4.0.30319\msbuild.exe

C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\amd64\MSBuild.exe
Technically, to get C# 6 features, I don't believe this is required, but hear me out.

在 BimlStudio 中,在逻辑或项目 View Pane 中,我右键单击我的项目,然后单击构建。

在“输出” Pane 中,我得到以下信息(请注意粗体错误):

    ------ Build ------    Working Directory: C:\PathToMyProject\BIMLStudioProject\output    MsBuild Executable: C:\WINDOWS\system32\cmd.exe    MsBuild Arguments:     To replicate this build with bimlc.exe. Use the bimlc.resp file:    bimlc.exe @"C:\PathToMyProject\BIMLStudioProject\output\BIMLStudioProject.mst.bimlc.resp"    Microsoft Windows [Version 10.0.17134.706]    (c) 2018 Microsoft Corporation. All rights reserved.    C:\PathToMyProject\BIMLStudioProject\output>C:\WINDOWS\system32\chcp.com 65001    Active code page: 65001    C:\PathToMyProject\BIMLStudioProject\output>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\amd64\MSBuild.exe @"C:/_Development/Test Projects/BIML/BIMLStudioProject/output/BIMLStudioProject.mst.resp"    'C:\Program' is not recognized as an internal or external command,    operable program or batch file.    C:\PathToMyProject\BIMLStudioProject\output>exit %ERRORLEVEL%    Build Failed

所以在 MSBuild 的路径中有空格是“verboten”?
我尝试在 MSBuild exe 的路径周围添加双引号。
那没有用。也许还有另一种方法可以做到这一点?
这不是我的主要问题,但如有任何帮助,我们将不胜感激。

因此,为了避开 BimlStudio IDE 的限制,我跳转到命令行并执行以下命令:

    cd "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\amd64\"    MSBuild.exe @"C:/PathToMyProject/BIMLStudioProject/output/BIMLStudioProject.mst.resp"

这将输出以下内容(滚动到底部以查看粗体错误):

    Microsoft (R) Build Engine version 15.9.21+g9802d43bc3 for .NET Framework    Copyright (C) Microsoft Corporation. All rights reserved.    Build started 11/8/2019 4:12:07 PM.    Project "C:\PathToMyProject\BIMLStudioProject\output\BIMLStudioProject.mst.ProjectView.bimlproj" on node 1 (default targets).    BimlCompilerBuild:    Message:: Biml Compiler Version 5.0.63501.0    Message:: Options:    $TargetBimlScriptPrecompiledAssemblyPackagePath =    $PrecompileBimlScript = False    $LicenseKey =    $DisplayMachineCode = False    $TransformationScriptSettings =    $TransformationScriptResourceAssembly =    $TransformationScriptBundle =    $PackageConfigurationPath = C:\PackageConfigurations    $DocumentationOutputPath = C:\PathToMyProject\BIMLStudioProject\documentation    $DocumentationSettings =    $DocumentationTemplate =    $BuildDocumentation = False    $CleanOutputFolder = True    $WarnAsError = False    $Warn = 4    $TargetPath = C:\PathToMyProject\BIMLStudioProject\output\\    $TempPath =    $WorkflowPath =    $BuildOnlyWithDependencies = False    @BuildOnly:    @SourceFiles:    ...C:\PathToMyProject\BIMLStudioProject\addedBiml\ScriptProjects\ST_4ed03a23e1db4022ad98d6615e195f26.biml    ...    @IncludeFiles:    @TemplateFiles:    @BimlDocSchemaGraphProfiles:    @BundleFiles:    @BundleSettings:    @ResponseFiles:    $SsisDeploymentModel = Project    $SsasVersion = Ssas2014    $SsasTabularVersion = SsasTabular2016    $SsisVersion = Ssis2014    $SqlVersion = SqlServer2014    $DdlBuildMode = SsisPackages    $SsisEncryptionPassword =    $SsisExternalColumnsQueryTimeout =    $ImportSsis = False    $ImportSsisOptionsPath =    $GetHelp = False    Message:: Processing Biml Code...    Message:: Running Project Transformers...    Message:: Running Custom Transformers...    Message:: Running Core Transformers...    Message:: Emitting SQL Server Assets...    Message:: 1/1 Emitting Project SagittaExtract.dtproj    Message::     1/1 Emitting Package PackageTemplate    In Script Project 'ST_4ed03a23e1db4022ad98d6615e195f26': \ScriptMain.cs(129,42): error : Error:: Unexpected character '$' [C:\PathToMyProject\BIMLStudioProject\output\BIMLStudioProject.mst.ProjectView.bimlproj]    In Script Project 'ST_4ed03a23e1db4022ad98d6615e195f26': \ScriptMain.cs(223,35): error : Error:: Unexpected character '$' [C:\PathToMyProject\BIMLStudioProject\output\BIMLStudioProject.mst.ProjectView.bimlproj]    Done Building Project "C:\PathToMyProject\BIMLStudioProject\output\BIMLStudioProject.mst.ProjectView.bimlproj" (default targets) -- FAILED.    Build FAILED.

请注意,我的脚本任务有一个无效字符“$”。这对应于做 string interpolation (C# 6.0 语言特性)。

那么我该怎么做才能在我的脚本任务中获得 C# 6 语言特性?

我试过使用 Biml 项目的默认 MSBuild 路径和版本,并添加/toolsversion 开关。

MSBuild.exe ... /tv:14.0

然后,改为使用VS 2017的64位MSBuild.exe

MSBuild.exe ... /tv:15.0

均无效。

如能提供帮助,我们将不胜感激。

谢谢。

最佳答案

Biml 编译器不支持 Roslyn

不幸的是,Biml 编译器 (bimlc) 不支持 Roslyn(我知道这是一个 future 的目标,但存在依赖关系,我不知道当前状态,我听说很快就会有新的下降,可能会支持SQL Server 2019 版)。

我会联系 Varigence 的人员进行确认。

路径名中的空格

已经永远吸进了 window 并且很可能会永远继续吸进。是的,您可以用双引号引起来,这样 "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\amd64\MSBuild.exe" 会起作用,但是什么如果其他东西需要引号或 $Diety-help-you,你必须将它作为参数传递给 xp_cmdshell 之类的东西,它只允许整个参数中的一个项目有一对双引号......是的,方法是使用 dos 8.3 命名约定的肮脏技巧,因为它们仍然有效。

从命令行,Win+R cmd.exe

cd /d C:\
dir /x

指示命令 shell 更改驱动器并转到 C 驱动器的根目录第二条命令中的/x

displays the short names generated for non-8dot3 file names.

所以你应该看到这样的输出

C:\>dir /x
Volume in drive C has no label.
Volume Serial Number is 3AB8-1C01

Directory of C:\

10/30/2019 04:26 PM <DIR> Dropbox
03/13/2019 06:07 PM <DIR> Intel
08/25/2019 01:32 PM <DIR> javajars
10/19/2019 03:33 PM <DIR> NEVERW~1 NeverwinterNights
03/12/2019 04:34 PM <DIR> NVIDIA
08/25/2019 02:01 PM <DIR> OnMyPath
03/18/2019 10:52 PM <DIR> PerfLogs
10/14/2019 09:57 PM <DIR> PROGRA~1 Program Files
10/19/2019 03:51 PM <DIR> PROGRA~2 Program Files (x86)
11/14/2018 07:16 PM <DIR> Python27
11/14/2018 07:16 PM <DIR> PYTHON~1 Python27amd64
06/22/2019 11:17 AM <DIR> Src
06/30/2019 08:45 PM <DIR> ssisdata
10/19/2019 01:52 PM <DIR> TEMP
06/28/2019 02:21 PM <DIR> tmp
07/30/2019 06:52 AM 110,312 UkLog.dat
05/28/2019 04:25 PM <DIR> Users
10/19/2019 03:54 PM <DIR> Windows
1 File(s) 110,312 bytes
17 Dir(s) 333,863,874,560 bytes free

NeverwinterNights 和 Python27amd64 太长(超过 8 个字符),这就是它们出现在第一个“名称”列中的原因。出现“Program Files”和“Program Files (x86)”是因为它们的名称中有空格(也超过 8 个字符)。

重要的是使用替代名称。模式并不难,它是前 6 个字符,较少的空格,然后是 ~# 从 1 到 9,直到你得到超过 9 个条目。

C:\PROGRA~2>dir /x mic*
Volume in drive C has no label.
Volume Serial Number is 3AB8-1C01

Directory of C:\PROGRA~2

02/21/2018 06:00 AM <DIR> MICROS~2 Microsoft Analysis Services
03/16/2018 02:17 AM <DIR> MICROS~2.NET Microsoft ASP.NET
06/22/2019 01:24 PM <DIR> MI7DE1~1 Microsoft Azure Storage Explorer
04/24/2019 06:48 PM <DIR> MICROS~4 Microsoft Help Viewer
03/01/2018 12:36 PM <DIR> MIF5BA~1 Microsoft Office
09/12/2018 04:35 PM <DIR> MI29F1~1 Microsoft OneDrive
10/24/2018 06:12 AM <DIR> MICROS~3 Microsoft SDKs
01/19/2019 10:48 AM <DIR> MI9950~1 Microsoft Silverlight
07/11/2019 08:10 PM <DIR> MICROS~1 Microsoft SQL Server
04/24/2019 06:50 PM <DIR> MIEFB9~1 Microsoft SQL Server Management Studio 18
11/14/2018 07:17 PM <DIR> MIB055~1 Microsoft Visual Studio
02/21/2018 06:02 AM <DIR> MICROS~2.0 Microsoft Visual Studio 10.0
05/28/2019 04:33 PM <DIR> MICROS~3.0 Microsoft Visual Studio 11.0
05/28/2019 04:33 PM <DIR> MICROS~4.0 Microsoft Visual Studio 12.0
05/28/2019 04:33 PM <DIR> MICROS~1.0 Microsoft Visual Studio 14.0
10/24/2018 06:07 AM <DIR> MIFDD6~1 Microsoft Web Tools
05/28/2019 07:23 PM <DIR> Microsoft.NET
0 File(s) 0 bytes
17 Dir(s) 333,865,095,168 bytes free

我敢肯定替代名称的工作原理已经被记录在案......25 年前 - 我认为这种废话出现在 Windows 95 中,但说真的,见鬼去吧。

因此,您正在寻找位于 x86 文件夹中的构建。不要让 Tab 完成帮助您更改目录,因为它将使用全名而不是短名。所以 cd progra~2

泡沫、冲洗、重复,直到您到达包含可执行文件的文件夹。长文件名无关紧要,因此路径中的 Professional 不会中断,它只是空格,但最终,您将位于带有 .exe 的文件夹中,然后您将获取路径。我采取了懒惰的方式,只是让 dir 使用 dir/s/b msbuild.exe

为我构建路径
C:\PROGRA~2\MIB055~1\2017\Enterprise\MSBuild\15.0\Bin>dir /s /b MSBuild.exe
C:\PROGRA~2\MIB055~1\2017\Enterprise\MSBuild\15.0\Bin\MSBuild.exe
C:\PROGRA~2\MIB055~1\2017\Enterprise\MSBuild\15.0\Bin\amd64\MSBuild.exe

此时,您应该能够将这些路径中的任何一个通过管道传输到 BimlStudio 中的 MSBuild,然后将它们保存到 .resp 文件中,看看是否解决了路径中的空间问题。

解锁 C# 6.0 功能

今天我了解到您可以在 SSIS 脚本任务和组件中使用 6.0 功能。

    public void Main()
{
string name = "mark";
string v = $"Hello, {name}!";
bool fireagain = false;
Dts.Events.FireInformation(0, "Really worked", v, string.Empty, 0, ref fireagain);

Dts.TaskResult = (int)ScriptResults.Success;
}

在我的输出窗口中

Information: 0x0 at Script Task, Really worked: Hello, mark!

注意:尝试将 Roslyn 功能添加到脚本任务可以 effectively disable Script Task debugging

关于c# - 如何让 BIML 编译器允许脚本任务、脚本组件中的 c#6 语言功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58775698/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com