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

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)

Related

Visual Studio 2019 set output directory for .tlog and .dll.recipe file

I have a project in Visual Studio and want all files generated during build under the build\ subdirectory.
I set all output options I could find but there is still a Debug\ folder created with the files: projectname.dll.recipe and subfolder projectname.xxxx.tlog which contains .tlog and .lastbuildstate files.
I know the .tlog files are from the MSBuild File Tracker, know idea what the .dll.recipe is.
How can I set the output directory for those files to $(OutDir)?
You can try the following steps:
Function 1
Open your project in VS IDE and then right-click on the project Properties-->Configuration Properties-->General--> change Intermediate Directory to ..\$(Configuration).
Then, rebuild your project to get what you want.
Function 2
1) add a file called Directory.Build.props in your solution folder like this:
2) add these content in the Directory.Build.props:
<Project>
<PropertyGroup>
<IntDir>..\$(Configuration)\</IntDir>
</PropertyGroup>
</Project>
3) close VS Instance, delete any Debug folder in your solution folder.
Then restart VS(enable the function of the Directory.Build.props) to open your solution to build again and the files will be under the $(OutDir) path.

Using a ** wildcard in an F# project causes Visual Studio to refuse to load the project

I've got an F# project with several additional files stored in many nested folders, creating a complex folder structure. The compiler doesn't need to know about them: all I need to do is to have them copied into the output directory at the end of the build process.
I tried adding my files using the ** wildcard:
<ItemGroup>
    <FilesToCopyToOutput Include="additionalData\**\*.*"/>
</ItemGroup>
It works fine when running MSBuild manually from PowerShell. However, when I attempt to open my project in Visual Studio (v. 2015), I get the following error message:
Cannot open F# project . This project uses
wildcards in the item specification. Wildcards in F# projects are not
currently supported.
Similarly, a C# project with the wildcards works just fine. I guess this has something to do with the fact that the order of files in an F# project matters and using the wildcards causes a problem if a user wants to reorder the files.
However, I'm wondering if there's anything that can be done in my particular case: I don't care if the files are available in VS or not: I just want them to be copied to the output folder.
Using a ** wildcard in an F# project causes Visual Studio to refuse to load the project
Indeed, Visual Studio 2017 is a good choose. I have test the ** wildcard in the Visual Studio 2015 and 2017, it works fine in the Visual Studio 2017 but not in the Visual Studio 2015, got the same error as you.
Since you could not change the tech stack to use Visual Studio 2017, I would like provide a workaround for this issue, you can check if it works for you.
Since you do not care if the files are available in VS or not, you just want them to be copied to the output folder, you can use a power shell script to copy the additionalData folder to the output folder, like:
Copy-Item -Path "ThePathForAdditionalData\additionalData" -Destination "ThePathForProject\bin\Debug" -recurse -Force
Then execute this power shell script with MSBuild task after build:
<Target Name="CopyMyFiles" AfterTargets="Build">
<Message Text="Copying files..."/>
<Exec Command="C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NonInteractive -executionpolicy Unrestricted -command "& { .\YourCopyFiles.ps1 } "" ></Exec>
</Target>
Hope this helps.
I assume FilesToCopyToOutput is the name you gave to an item collection, and the question is how to stop the old F# compiler from thinking it should handle it?
I suspect what you want to do though is to treat an entire folder as content items and copy them to the output folder :
<Content Include="additionalData\**\*.*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
Copy Task
If you want to copy items with an MSBuild task you can use Copy. You should be able to write :
<ItemGroup>
<MyAdditionalData Include="additionalData\**\*.*" />
</ItemGroup>
<Target Name="CopyFiles">
<Copy
SourceFiles="#(MyAdditionalData)"
DestinationFolder="$(OutputPath)"
/>
</Target>
The Include attribute allows selecting multiple files that can be used as arguments to a task. Exclude is used to exclude files. You can specify a Condition attribute too, eg to run the task only for Release or Debug configuration. $(OutputPath) is one of the MSBuild properties that can be used in paths.
How to: Exclude Files from the Build shows how you can combine all those attributes to process specific items in a directory, eg:
<JPGFile
Include="Images\**\*.jpg"
Exclude = "Images\**\Version2\*.jpg"/>
This will include all files in the Images directory except those in Version2
Using Post-build events
Most people though didn't use MSBuild until the latest simplified format.
The most common way to copy files after build is to use a post-build event from the project's property pages, eg :
xcopy $(ProjectDir)additionalData\*.* $(TargetDir) /s /e
$(ProjectDir) and $(TargetDir) are replacement macros that point to the projects' folder and output folder. The list of all macros is available in Pre-build Event/Post-build Event Command Line Dialog Box.

VS2017: Compilation does not copy and deletes Result Files

My application uses some third party libraries and data files.
To place third party files in the results folder at compile time, I use this setting in the c # project file:
<ItemGroup Condition="'$(Platform)' == 'x86'">
<Content Include="..\..\ThirdParty\SQLite\3.27.2\x86\SQLite.Interop.dll" CopyToOutputDirectory="PreserveNewest" Link="ThirdParty\SQLite\3.27.2\x86\SQLite.Interop.dll" />
<Content Include="..\..\ThirdParty\SQLite\3.27.2\x86\System.Data.SQLite.dll" CopyToOutputDirectory="PreserveNewest" Link="ThirdParty\SQLite\3.27.2\x86\System.Data.SQLite.dll" />
</ItemGroup>
That third party files must be copied while Preserving the newest to the result destination folder.
When the compilation is clean (Clean then Build or Rebuild) for the first time all is generated and copied correctly, the application runs correctly by running it from visual studio by pressing the Start/Play button.
So when closing the application or stop from visual studio then Start again the previus files copied correctly seem deleted.
Then if I clean and recompile the solution all the files are copied correctly to the destination folder.
More Info:
It happens too when generating both Result and Debug, in x86 and also in x64.
Windows 10 x64; Visual Studio Community 2017 v15.19.20; MSBuild.
The same happened with Visual Studio Professional 2015 Update 3.
Apparently it is not the error of dependencies from other dependencies because in the clean compilation the files are copied correctly.

Compile TypeScript on build

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)

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?

Resources