如何通过Microsoft.typescript.msbuild将Visual Studio复制JS文件复制JS文件?
我在 Visual Studio 2022 中有一个非WEB项目(WPF),UI使用HTML/CSS/JavaScript。我也想在“构建”上编译打字稿,然后将编译的JS文件复制到构建文件夹中。
这是我的 tsconfig.json
文件,因此它将 scripts
文件夹中的文件编译到 webapp \ js
文件夹中(脚本文件夹不会复制,并且是不是Neccessary)
{
"compileOnSave": true,
"compilerOptions": {
"outDir": "WebApp/js/",
"rootDir": "Scripts/"
// Other options
},
"exclude": [
"WebApp/"
]
}
这是我的 csproj
文件,以包含并复制 webApp
文件夹中的所有文件(请注意 tsconfig.json
是内容,所以是
> Microsoft.typescript.msbuild
遵循该文件中的说明):
<ItemGroup>
<None Include="WebApp\**">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Content Include="tsconfig.json" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.TypeScript.MSBuild" Version="4.6.4">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<!-- Other items -->
问题是,显然,在 typescript构建之前,副本已执行,因此除非我两次构建项目,否则我的文件永远不会复制。
我尝试添加a 任务以及 AfterTargets
设置为 build> build
,但即使是复制的文件也在打字稿汇编之前。
如何在复制之前制作打字稿汇编任务?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现我创建的目标应该具有
aftertargets
, compileTypescriptwithtsconfig 值。由于运行dotnet build -verbosity:正常
获得了实际目标的所有名称。我还在复制的
sourcefiles
属性之前使用了错误的符号($
而不是@
),以便没有复制文件。I found out the target I create should have
AfterTargets
withCompileTypeScriptWithTSConfig
value. I got the value thanks to runningdotnet build -verbosity:normal
to get all the name of actual targets.I also used a wrong symbol (
$
instead of@
) in the Copy'sSourceFiles
attribute before so no file got copied.