首页 > 编程语言 >Example of using Target file in C# project

Example of using Target file in C# project

时间:2023-01-14 14:22:28浏览次数:60  
标签:files use Target C# project file your target

What is target file ?

projects use .target files to define which files should be imported into the project during the build process (more info).

 

How to use it ?

1.in order to use target files firstly you need to tell your Visual C# project to use this future by adding below line to the project file (.csproj).

<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

2.Then you need to import the targetFile address as below

my target file name is “TargetFileApp.csproj.targets“

3.In the next step you will ask the compiler when to do the target files task

<Target Name="AfterBuild">
  <CallTarget Targets="CopyPackageContent" />
</Target>

A target never build twice but you can order the build by using BeforeTargets and AfterTargets (read more) .

by above line it goes to my target file and looking for “CopyPackageContent” element.

4.now you can add the your desirable tasks to your target file

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
   <TestBase Include="Test\*.*" Exclude="Test\*.etc" />
  </ItemGroup>
  <Target Name="CopyPackageContent">
  <Copy SourceFiles="@(TestBase)" DestinationFiles="@(TestBase-&gt;'$(OutDir)%(RecursiveDir)%(Filename)%(Extension)')" />
    <Warning Text="Content copied from package TestBase.Base to the output folder. Cleaning the project/solution will not delete these files." />
    </Target>
</Project>

In the ItemsGroup you can define your addresses and filter them with Exclude attribute . for instance in this case, it is looking for all the files which exist in Test folder except the one has .etc extension.

when the project is build the compiler find the “CopypackageContent” element in the target file and then start copying from pre defined addresses to destination address (more info about copy task) .

download the whole source of TargetFileApp from my GitHub.

added : I also make a simple application to generate the target file for CSharp project.

标签:files,use,Target,C#,project,file,your,target
From: https://www.cnblogs.com/bruce1992/p/17051731.html

相关文章

  • 首次打开apache-TomCat的一些问题
    问题①:点击bin文件夹下的startup.bat后直接闪退。解决:检查电脑系统环境变量中的这三个(右键此电脑->属性->高级系统设置->高级->环境变量(看下面的系统变量)),如图......
  • 关于tomcat控制台输出乱码问题
     点击这个 添加:   -Dfile.encoding=UTF-8如图 ......
  • 什么是webpack
    一、webpack是什么webpack是一个用于现代JavaScript应用程序的静态模块化打包构建工具模块化:服务端Common.js(module.exports,require),浏览器端ESM......
  • Elasticsearch中的refresh和flush操作指南(es数据写入但是查询不到问题)
    在今天的文章里,我们来主要介绍一下Elasticsearch的refresh及flush两种操作的区别。如果我们从字面的意思上讲,好像都是刷新的意思。但是在Elasticsearch中,这两种操......
  • elasticsearch性能调优
    索引的创建需要配置mapping与setting两部分。索引的mapping常用数据类型text、keyword、number、array、range、boolean、date、geo_point、ip、nested、object。text:......
  • Elasticsearch查询调优
    前言一个系统查询慢往往是由多种因素造成的,在处理集群查询慢的问题上,先将问题分解。1)需要观察是系统哪种资源受限,例如内存、CPU或磁盘IO等,是否存在硬件瓶颈;2)要确定......
  • Centos7.6安装nodejs
    1.直接yuminstallnodejs安装后没有npm,搜索后说时要先执行curl--silent--locationhttps://rpm.nodesource.com/setup_10.x|bash-,再进行yuminstall,因内网环境就放......
  • Tapdata Cloud 场景通关系列:将数据导入阿里云 Tablestore,获得毫秒级在线查询和检索能
    【前言】作为中国的“Fivetran/Airbyte”,TapdataCloud自去年发布云版公测以来,吸引了近万名用户的注册使用。应社区用户上生产系统的要求,TapdataCloud3.0将正式推......
  • Loadrunner11创建脚本、打开vugen、controller、analysis超级慢的解决方法
    问题现象启动的时候很慢,即打开LR11的启动程序很慢;点击创建脚本的时候也很慢:打开脚本很慢:创建controller场景很慢:分析结果的时候很慢:解决方法:如果你......
  • LeetCode.24 两两交换链表中的结点
    1.题目给你一个链表,两两交换其中相邻的节点,并返回交换后链表的头节点。你必须在不修改节点内部的值的情况下完成本题(即,只能进行节点交换)。 2.代码/***Definitionforsin......