Compile TypeScript on build - visual-studio

I have a ASP.NET Core project (a .xproj file) containing some TypeScript files. When I build this project, all .ts files are automatically transpiled to .js files. Also if I modify and then save a .ts file its .js is generated (compileOnSave). This is nice.
In the same solution I have a .NET Core Class Library (also a .xproj file). This project also contains a tsconfig.json file and some TypeScript files. The compileOnSave feature works nice, but when I build the project, the .ts files are not compiled. This means that I need to modify and save the .ts file manually to generate the .js file.
How do I have to configure my class library project so that .js files are created when I build the project?
I'm working with Visual Studio 2015 Update 3 with the "TypeScript for Microsoft Visual Studio" version 2.0.6.0 extension installed.

Add
<Import Project="$(VSToolsPath)\DotNet.Web\Microsoft.DotNet.Web.targets" Condition="'$(VSToolsPath)' != ''" />
to the xproj file to get typescript built to JS (got the line from my ASP.NET Core - .xproj file)

Related

How to ALWAYS include new files in a folder in Visual Studio 2017

I have a project in visual studio 2017 for making a WinJS UWP windows 10 app. I'm using babel to compile some files from one folder and put them in another -- > jsx/src includes my .jsx files, and they get compiled into jsx/out.
I've set up a babel watcher to watch the jsx/src file and output a new file to jsx/out, but for now every new file I add, I have to manually add it in visual studio so that it shows in the folder. I'd like this to be automatic.
I have the answer for this now! Didn't realize this was left unanswered.
The answer is to modify the project.jsproj file directly. Open your project folder, find the file called {projectname}.jsproj and open it in your favorite text editor.
For my use case, I wanted to:
Fully include the 'bundle.js' file in /jsx/out
Include, but not export with the build, any .js / .jsx files in /jsx/src
So I added these lines:
<None Include="jsx\src\**\*.jsx" />
<None Include="jsx\src\**\*.js" />
<Content Include="jsx\out\bundle.js" />
"None" means the files are shown in Visual Studio, still remain debuggable, but don't end up getting put in with the files when you build it for the windows store.
Now any new files get included in when they're added to the appropriate folder (sometimes you might have to force reload the project to see them)

Suppress warnings/errors in Visual Studio 2017 for certain file

I have a project which is using TypeScript and some external libraries.
I'm searching a way to block all errors and warnings for all .js, .ts, .d.ts etc. files in node_modules folder and the folder with other libraries which relative path to the project root is assets/plugins . I've tried creating a .eslintignore file with the following content:
./node_modules/*
./assets/plugins/*
and also
./node_modules/**/*.js
./node_modules/**/*.ts
./node_modules/**/*.d.ts
./assets/plugins/**/*.js
./assets/plugins/**/*.ts
./assets/plugins/**/*.d.ts
but this didn't work.
Just to recap, I want to block errors and warnings for those files only and remain visible for all other files in the project.
P.S.: All those errors and warnings in .ts and .js files are visible only in Visual Studio 2017 when the project is opened in Visual Studio 2015 there are no errors and warnings.
Adding an .eslintignore to the root of the project, containing the following, and then restarting VS did the trick for me (for now at least)
**/*.d.ts
**/node_modules/*
In order to suppress all warnings for node_modules (both ECMAScript and TypeScript) you should create an .eslintignore file with the following content:
**/*.d.ts
**/node_modules/*
**/assets/plugins/*
and also create configuration for the typescript compiler (tsconfig.json file) in the project root containing the following:
{
"exclude": [
"node_modules/*",
"assets/plugins/*"
]
}

Why does Visual Studio publish packages.config too?

When I use the option Publish... selecting as target the file system in Visual Studio 2015 it compiles the code, do the XML transformation in the Web.config files and copy the files to the folder I specified.
It does not copy any *.cs file as expected since it is compiled.
Something that I don't understand is why it publishes the Nuget Config file (packages.config), after all, the files needed are already in the bin folder.
I found this question that says how to avoid but not the reason they decided this file would be usable on the server.
Can I stop VS from publishing packages.config?
Anyone know why packages.config end up in the publish folder?

Conditionally add content file to visual studio C++ project

I have a visual C++ project for a DLL and a setup project for it. In the installer i've added the content files of my project.
Is there a way to add a file as a content file depending on if you are compiling debug or release? I want to include boost_date_time-vc100-mt-gd-1_51.dll if I compile under debug and boost_date_time-vc100-mt-1_51.dll if I compile under release.
My additional deps looks like this
Shell32.lib;libzmq.lib;log4cxx.lib;boost_date_time-vc100-mt-gd-1_51.lib;...
Under additional library directories i've added the path to all these .lib files which also contains their respective .dll files
I've tried the following with no success...
Added a Custom build step to run before build that copies the correct dll files to the OutDir and set the Output of this custom build step to be the dll files.
Conditionally include a content file by manually editing the vcxproj file. If configuration was release mode I would set the non-debug version as deployment content and the debug version to false and vice versa for Debug mode. This looked something like this,
<ItemGroup Condition="'$(Configuration)'=='Release'">
<None Include="boost_date_time-vc100-mt-1_51.dll ">
<DeploymentContent>true</DeploymentContent>....
</None></ItemGroup
Neither of these worked however. The second option seemed to always default to debug mode no matter how I built my project.
When you add a dependency, you can add it to one configuration or all configurations:
[This picture is of VS 2012, but 2010 and 2008 look pretty much the same.]
So, you pick the configuration you want to modify at the top-left, then add the library to the additional dependencies. Note that what you add here will be the .lib file associated with a DLL, not the dll itself (the compiler will make the executable depend on the DLL because you link with its .lib file).

Post build event to include a file to the project

I'd like to copy a file and include the file in the web project and would like to do this as a part of the Pre/Post build events.
My understanding is that these events support DOS commands and I can use xcopy for copying a file, but I am not sure how I would update the csproj file to include the file in the project.
Do you need the file to be in the output directory or actually be part of the .csproj file ?
If you really want to update the csproj file then try customising the AfterBuild target in the csproj file of the startup project in your solution. All csproj files are msbuild files and you can use the full power or msbuild including callling any task. Right click on the project in the solution explorer, select unload project and then edit project. Then customise the AfterBuild target to change the particular csproj file you want. Use built in tasks or the excellent extension pack for changing the file. Finally reload the project.

Resources