After upgrading to TS 0.9, I get TS5007: can't solve the link file: how can I fix it?

We recently upgraded to TS 0.9 and some of the TS files that previously worked fine no longer compile, and we get:

TS5007: Unable to resolve link file: ...

How can i fix this?

+4
source share
3 answers

I started with two files from our source that I could work in isolation.

One of them was a definition file (* .d.ts), and the other was a normal file with implementations for interfaces in the definition file. The definition file gave the error described above.

Then I started to remove the pieces of code from the definition file until the error disappears and I was able to compile it.

This indicated that there was a problem in the comments in this file, as the problem arose / disappeared when I added / removed some comments.

I started experimenting with the position and content of the comments and found that the comments were on the line or on their own line did not change the situation. However, comments with non-ASCII characters caused the problem!

Armed with this information, I went to the Typescript codeplex page to report an error and found that someone already had it.

Unable to process characters without ASCII Unicode characters

Thus, at the moment, the solution should not use Unicode characters in your code.

So now the solution is to save the file in Unicode encoding.

TypeScript 0.9 - Could not find file

+7
source

I also ran into this problem, however it had nothing to do with coding.

If you have too many files with TypeScriptCompile Build Actions in Visual Studio, and you use the custom Exec command line in your csproj BeforeBuild or AfterBuild , you can see the same โ€œcannot resolve the linked fileโ€.

If you have too many files or many files with relatively long paths (myproj / scripts / reallylongfoldername / reallylongilename.ts), they cannot fit into command line arguments. Look carefully at the error. For me, just adding a new file.ts project to the project caused an error:

Cannot resolve the reference file: C: \ Path \ To \ Project \ scripts \ file.s

This is not a typo above. The compiler actually removed โ€œtโ€ from โ€œfile.tsโ€ to match the command line, and since the file โ€œfile.sโ€ does not exist, I got an error.

The solution was to add a custom build target. I only ran into this problem after installing Visual Studio 2013, as it wants all definition files to have Type BuildCompile Build Action. So I just copied these 2 files to the Build folder under my solution:

SolutionFolder \ Build \ Microsoft.TypeScript.Default.props

 <?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <TypeScriptRemoveComments>false</TypeScriptRemoveComments> <TypeScriptNoImplicitAny>false</TypeScriptNoImplicitAny> <TypeScriptNoResolve>false</TypeScriptNoResolve> <TypeScriptGeneratesDeclarations>false</TypeScriptGeneratesDeclarations> <TypeScriptModuleKind>amd</TypeScriptModuleKind> <TypeScriptOutFile></TypeScriptOutFile> <TypeScriptOutDir></TypeScriptOutDir> <TypeScriptSourceMap>true</TypeScriptSourceMap> <TypeScriptMapRoot></TypeScriptMapRoot> <TypeScriptSourceRoot></TypeScriptSourceRoot> <TypeScriptTarget>ES5</TypeScriptTarget> <TypeScriptAdditionalFlags></TypeScriptAdditionalFlags> <TypeScriptEnableCompileOnSave>true</TypeScriptEnableCompileOnSave> </PropertyGroup> </Project> 

SolutionFolder \ Building \ Microsoft.TypeScript.targets

 <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <VsToolsPath Condition="'$(VsToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VsToolsPath> </PropertyGroup> <UsingTask TaskName="TypeScript.Tasks.VsTsc" AssemblyFile="$(VSToolsPath)\TypeScript\TypeScript.tasks.dll" /> <PropertyGroup> <CompileDependsOn> CompileTypeScript; $(CompileDependsOn); </CompileDependsOn> </PropertyGroup> <PropertyGroup> <PublishPipelineCollectFilesCore> $(PublishPipelineCollectFilesCore); TypeScriptCollectPublishFiles; </PublishPipelineCollectFilesCore> </PropertyGroup> <PropertyGroup Condition="'$(TypeScriptBuildConfigurations)' == ''"> <TypeScriptCompileOnSaveEnabled Condition="'$(TypeScriptEnableCompileOnSave)' != 'false'">true</TypeScriptCompileOnSaveEnabled> <PreferredUILang Condition="'$(BuildingInsideVisualStudio)' == 'true' and '$(PreferredUILang)' == ''">$([System.Globalization.CultureInfo]::CurrentUICulture.Name)</PreferredUILang> <TypeScriptBuildConfigurations Condition="'$(TypeScriptRemoveComments)' == 'true'">$(TypeScriptBuildConfigurations) --removeComments</TypeScriptBuildConfigurations> <TypeScriptBuildConfigurations Condition="'$(TypeScriptNoImplicitAny)' == 'true'">$(TypeScriptBuildConfigurations) --noImplicitAny</TypeScriptBuildConfigurations> <TypeScriptBuildConfigurations Condition="'$(TypeScriptNoResolve)' == 'true'">$(TypeScriptBuildConfigurations) --noResolve</TypeScriptBuildConfigurations> <TypeScriptBuildConfigurations Condition="'$(TypeScriptGeneratesDeclarations)' == 'true'">$(TypeScriptBuildConfigurations) --declaration</TypeScriptBuildConfigurations> <TypeScriptBuildConfigurations Condition="'$(TypeScriptModuleKind)' != ''">$(TypeScriptBuildConfigurations) --module $(TypeScriptModuleKind)</TypeScriptBuildConfigurations> <TypeScriptBuildConfigurations Condition="'$(TypeScriptOutFile)' != ''">$(TypeScriptBuildConfigurations) --out &quot;$(TypeScriptOutFile)&quot;</TypeScriptBuildConfigurations> <TypeScriptBuildConfigurations Condition="'$(TypeScriptOutDir)' != ''">$(TypeScriptBuildConfigurations) --outDir &quot;$(TypeScriptOutDir)&quot;</TypeScriptBuildConfigurations> <TypeScriptBuildConfigurations Condition="'$(TypeScriptSourceMap)' == 'true'">$(TypeScriptBuildConfigurations) --sourcemap</TypeScriptBuildConfigurations> <TypeScriptBuildConfigurations Condition="'$(TypeScriptTarget)' != ''">$(TypeScriptBuildConfigurations) --target $(TypeScriptTarget)</TypeScriptBuildConfigurations> <TypeScriptBuildConfigurations Condition="'$(TypeScriptNoResolve)' == 'true'">$(TypeScriptBuildConfigurations) --noResolve</TypeScriptBuildConfigurations> <TypeScriptBuildConfigurations Condition="'$(TypeScriptAdditionalFlags)' != ''">$(TypeScriptBuildConfigurations) $(TypeScriptAdditionalFlags)</TypeScriptBuildConfigurations> <TypeScriptBuildConfigurations Condition="'$(TypeScriptMapRoot)' != ''">$(TypeScriptBuildConfigurations) --mapRoot &quot;$(TypeScriptMapRoot)&quot;</TypeScriptBuildConfigurations> <TypeScriptBuildConfigurations Condition="'$(TypeScriptSourceRoot)' != ''">$(TypeScriptBuildConfigurations) --sourceRoot &quot;$(TypeScriptSourceRoot)&quot;</TypeScriptBuildConfigurations> <TypeScriptBuildConfigurations Condition="'$(TypeScriptCodePage)' != ''">$(TypeScriptBuildConfigurations) --codepage $(TypeScriptCodePage)</TypeScriptBuildConfigurations> <TypeScriptBuildConfigurations Condition="'$(PreferredUILang)' != ''">$(TypeScriptBuildConfigurations) --locale $(PreferredUILang)</TypeScriptBuildConfigurations> </PropertyGroup> <PropertyGroup> <TscToolPath Condition="'$(TscToolPath)' == ''">$(MSBuildProgramFiles32)\Microsoft SDKs\TypeScript</TscToolPath> <TscToolExe Condition="'$(TscToolExe)' == ''">tsc.exe</TscToolExe> <TscYieldDuringToolExecution Condition="'$(TscYieldDuringToolExecution)' == ''">true</TscYieldDuringToolExecution> </PropertyGroup> <ItemGroup> <PropertyPageSchema Include="$(MSBuildThisFileDirectory)\$(LangName)\TypeScriptProjectProperties.xaml;"> <Context>Project;BrowseObject</Context> </PropertyPageSchema> </ItemGroup> <ItemGroup> <ProjectCapability Include="TypeScript" /> </ItemGroup> <Target Name="CompileTypeScript" Condition="'$(BuildingProject)' != 'false'"> <VsTsc ToolPath="$(TscToolPath)" ToolExe="$(TscToolExe)" Configurations="$(TypeScriptBuildConfigurations)" FullPathsToFiles="@(TypeScriptCompile)" YieldDuringToolExecution="$(TscYieldDuringToolExecution)" OutFile="$(TypeScriptOutFile)" OutDir="$(TypeScriptOutDir)" > <Output TaskParameter="GeneratedJavascript" ItemName="GeneratedJavascript" /> </VsTsc> </Target> <Target Name="TypeScriptCollectPublishFiles"> <Message Text="Adding to FilesForPackagingFromProject: @(GeneratedJavascript->'%(Identity)')"/> <ItemGroup> <FilesForPackagingFromProject Include="@(GeneratedJavascript->'%(Identity)')"/> </ItemGroup> </Target> </Project> 

Then I modified the csproj file of the project, which stores all these typescript files. Place the following line in front of the line <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> (near the top of the file):

 <Import Project="..\Build\Microsoft.TypeScript.Default.props" /> 

Then put the following on the right after the line <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> (near the bottom of the file):

 <Import Project="..\Build\Microsoft.TypeScript.targets" /> 

This will build typescript in both VS 2012 and 2013. You can also add a condition condition for each import if you have a special assembly configuration for building ts:

 <Import Project="..\Build\Microsoft.TypeScript.Default.props" Condition="'$(Configuration)' == 'DebugBuildTs' Or '$(Configuration)' == 'Release'" /> <Import Project="..\Build\Microsoft.TypeScript.targets" Condition="'$(Configuration)' == 'DebugBuildTs' Or '$(Configuration)' == 'Release'" /> 
+2
source

I also ran into this problem. This problem only occurred after I installed Visual Studio 2015 using web development tools, when I used to use Visual Studio 2013, where everything worked fine. Now it will build and work in VS2015, but will cause this error if I try to build it on VS2013. In the end, I just transferred my development to VS2015.

0
source

Source: https://habr.com/ru/post/1487013/


All Articles