2016-12-19 127 views
0

我想構建一個解決方案(VS 2017 RC),它使用TypeScript 2.1。當它建立在Visual Studio Team Services中失敗,出現以下錯誤信息(其中包括許多其他的)Angular2構建失敗Visual Studio團隊服務

C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.8\tsc.exe --project "C:\a\1\s\Angular\tsconfig.json" 
[error]Angular\node_modules\rxjs\Observable.d.ts(29,33): Error TS1138: Build: Parameter declaration expected. 

從Google檢索似乎因爲transcompiler過時的版本出現此錯誤的。我如何獲得VSTS使用2.1版本?這甚至有可能嗎?

這裏是我的package.json文件,以澄清我在做什麼:

{ 
    "name": "ng2-startvs", 
    "version": "1.0.0", 
    "description": "", 
    "main": "index.js", 
    "scripts": { 
    "start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\"", 
    "lite": "lite-server", 
    "tsc": "tsc", 
    "tsc:w": "tsc -w", 
    "typings": "typings", 
    "postinstall": "typings install" 
    }, 
    "keywords": [], 
    "author": "", 
    "license": "ISC", 
    "devDependencies": { 
    "@types/jquery": "^2.0.34", 
    "concurrently": "^3.1.0", 
    "lite-server": "^2.2.2", 
    "typescript": "^2.1.4", 
    "typings": "^2.0.0" 
    }, 
    "dependencies": { 
    "@angular/common": "^2.3.0", 
    "@angular/compiler": "^2.3.0", 
    "@angular/core": "^2.3.0", 
    "@angular/forms": "^2.3.0", 
    "@angular/http": "^2.3.0", 
    "@angular/platform-browser": "^2.3.0", 
    "@angular/platform-browser-dynamic": "^2.3.0", 
    "@angular/router": "^3.3.0", 
    "core-js": "^2.4.1", 
    "reflect-metadata": "^0.1.8", 
    "rxjs": "^5.0.0-beta.12", 
    "systemjs": "^0.19.41", 
    "zone.js": "^0.7.2" 
    } 
} 

我tsconfig現在是這樣的:

{ 
    "compilerOptions": { 
    "target": "es5", 
    "module": "commonjs", 
    "moduleResolution": "node", 
    "sourceMap": true, 
    "emitDecoratorMetadata": true, 
    "experimentalDecorators": true, 
    "removeComments": false, 
    "noImplicitAny": false, 
    "outDir": "dist" 
    }, 
    "exclude": [ 
    "node_modules", 
    "typings" 
    ] 
} 

這裏是我的構建定義:

<?xml version="1.0" encoding="utf-8"?> 
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 
    <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.Default.props" Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.Default.props')" /> 
    <PropertyGroup> 
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> 
    <ProjectGuid>{B2A7EAE0-F8C3-4B1E-A3BB-F1F4ECB4A30D}</ProjectGuid> 
    <ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids> 
    <OutputType>Library</OutputType> 
    <OutputPath>bin</OutputPath> 
    <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion> 
    <DebugType>full</DebugType> 
    <DebugSymbols>true</DebugSymbols> 
    <TypeScriptToolsVersion>2.1</TypeScriptToolsVersion> 
    <UseIISExpress>true</UseIISExpress> 
    <IISExpressSSLPort /> 
    <IISExpressAnonymousAuthentication /> 
    <IISExpressWindowsAuthentication /> 
    <IISExpressUseClassicPipelineMode /> 
    <UseGlobalApplicationHostFile /> 
    </PropertyGroup> 
    <ItemGroup> 
    <Service Include="{4A0DDDB5-7A95-4FBF-97CC-616D07737A77}" /> 
    </ItemGroup> 
    <ItemGroup> 
    <Content Include="app\app.component.css" /> 
    <Content Include="app\app.component.html" /> 
    <Content Include="index.html" /> 
    <Content Include="systemjs.config.js" /> 
    <Content Include="web.config" /> 
    </ItemGroup> 
    <ItemGroup> 
    <Content Include="package.json" /> 
    <Content Include="tsconfig.json" /> 
    <Content Include="typings.json" /> 
    <None Include="web.Debug.config"> 
     <DependentUpon>web.config</DependentUpon> 
    </None> 
    <None Include="web.Release.config"> 
     <DependentUpon>web.config</DependentUpon> 
    </None> 
    </ItemGroup> 
    <ItemGroup> 
    <TypeScriptCompile Include="app\app.component.ts" /> 
    <TypeScriptCompile Include="app\app.module.ts" /> 
    <TypeScriptCompile Include="app\main.ts" /> 
    <TypeScriptCompile Include="app\shared\models\counter.ts" /> 
    <TypeScriptCompile Include="app\counters\counter-insert.component.ts" /> 
    <TypeScriptCompile Include="app\counters\counter-edit.component.ts" /> 
    </ItemGroup> 
    <PropertyGroup> 
    <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">12.0</VisualStudioVersion> 
    </PropertyGroup> 
    <PropertyGroup> 
    <RootNamespace>AngularCounter</RootNamespace> 
    </PropertyGroup> 
    <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> 
    <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\WebApplications\Microsoft.WebApplication.targets" Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\WebApplications\Microsoft.WebApplication.targets')" /> 
    <ProjectExtensions> 
    <VisualStudio> 
     <FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}"> 
     <WebProjectProperties> 
      <UseIIS>True</UseIIS> 
      <AutoAssignPort>True</AutoAssignPort> 
      <DevelopmentServerPort>23097</DevelopmentServerPort> 
      <DevelopmentServerVPath>/</DevelopmentServerVPath> 
      <IISUrl>http://localhost:23098/</IISUrl> 
      <NTLMAuthentication>False</NTLMAuthentication> 
      <UseCustomServer>False</UseCustomServer> 
      <CustomServerUrl> 
      </CustomServerUrl> 
      <SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile> 
     </WebProjectProperties> 
     </FlavorProperties> 
    </VisualStudio> 
    </ProjectExtensions> 
    <PropertyGroup Condition="'$(Configuration)' == 'Debug'"> 
    <TypeScriptRemoveComments>false</TypeScriptRemoveComments> 
    <TypeScriptSourceMap>true</TypeScriptSourceMap> 
    </PropertyGroup> 
    <PropertyGroup Condition="'$(Configuration)' == 'Release'"> 
    <TypeScriptRemoveComments>true</TypeScriptRemoveComments> 
    <TypeScriptSourceMap>false</TypeScriptSourceMap> 
    </PropertyGroup> 
    <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets" Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets')" /> 
</Project> 
+0

可能要檢查是否tsc 2.1安裝在您的構建服務器上。之後,仔細檢查你的構建過程,看看如何調用tsc。希望有所幫助。 – Vinny

回答

1

Hosted Agent上的TypeScript的最高版本是2.0.6。

請按以下步驟,如果你正在使用Visual Studio構建構建項目來處理這個問題:

  1. 添加/安裝Microsoft.TypeScript.MSBuild package到項目
  2. 編輯您的項目文件(.csproj)

    a。)配置MSBuild使用NuGet包的道具文件。

    <Import Project="..\packages\Microsoft.TypeScript.MSBuild.2.1.4\build\Microsoft.TypeScript.MSBuild.props" Condition="Exists('..\packages\Microsoft.TypeScript.MSBuild.2.1.4\build\Microsoft.TypeScript.MSBuild.props')" /> 
    <!--<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.Default.props" Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.Default.props')" />--> 
    

    b)將MSBuild配置爲使用NuGet包的目標文件。

    <Import Project="..\packages\Microsoft.TypeScript.MSBuild.2.1.4\build\Microsoft.TypeScript.MSBuild.targets" Condition="Exists('..\packages\Microsoft.TypeScript.MSBuild.2.1.4\build\Microsoft.TypeScript.MSBuild.targets')" /> 
    <!--<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets" Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets')" />--> 
    

    如果是對.NET核心項目,該代碼添加到.xproj文件

    <TypeScriptToolsVersion>2.1.4</TypeScriptToolsVersion> 
    <TscToolPath>C:\Users\[user account]\.nuget\packages\Microsoft.TypeScript.MSBuild\2.1.4\tools\tsc</TscToolPath> 
    

如果您是直接使用TSC命令,例如,quickstart demo的部分:NPM運行TSC ,TypeScript依賴關係在package.json中定義,相應的TypeScript將在npm install構建步驟中安裝,然後在通過npm構建步驟/任務調用npm run tsc命令時使用相應版本的tsc工具進行編譯。

另一方面,有TypeScript compiler package,所以你可以在你的項目中包含這個包,然後通過該包中的tsc.exe工具編譯打字稿文件。

+0

感謝您的回覆。我已經包含了上面的package.json命令來顯示我正在做的更清楚的事情。我認爲這意味着我直接使用tsc命令?我按照建議將TypeScript的版本更改爲2.0.6,但構建仍然失敗,並顯示相同的錯誤消息。我不清楚上述建議的哪一部分適用於我的情況。謝謝 – johnstaveley

+0

@johnstaveley首先,您爲什麼需要在node_modules中編譯typescript文件?如果不需要編譯,只需在tsconfig.json中排除該文件夾即可。其次,嘗試將「tscv」:「tsc --version」添加到package.json的Script部分,然後通過npm build步驟/任務調用npm run tscv。第三,提供構建定義的詳細步驟。 –

+0

根據這一https://www.typescriptlang.org/docs/handbook/tsconfig-json.html的node_modules目錄默認情況下應 – johnstaveley

相關問題