使用相对路径在 MSBuild 中移动文件

发布于 2024-09-16 07:13:45 字数 504 浏览 3 评论 0原文

我正在尝试将某种类型的所有文件移动到相对于文件本身的目录,我想知道是否可以使用 MSBuild。

基本上,我使用 Microsoft AJAX Minifier 来缩小网站上的所有 Javascript 和 CSS 文件。这会将 .min.js 和 .min.css 文件输出到与 Javascript 和 CSS 文件相同的目录中。因为我的网站有很多皮肤,所以JS和CSS文件位于很多目录中。我希望能够添加一个在 AJAX Minifier 之后运行的任务,将所有 .min.js 和 .min.css 文件移动到相对于文件位置的 /min/ 。因此 /Skin1/somescript.min.js 将移至 /Skin1/min/somescript.min.js,而 /Skin2/somescript.min.js 将移至 /Skin2/somescript.min.js。

我知道完成复制/移动的唯一方法需要了解绝对目录(或者我应该说相对于项目文件的目录),但我似乎找不到一种基于相对于文件的目录进行移动的方法我要搬家了

这可以做到吗?

I'm trying to move all files of a certain type to a directory relative to the file itself and I'm wondering if it's possible using MSBuild.

Basically, I'm using the Microsoft AJAX Minifier to minify all Javascript and CSS files on my site. This outputs .min.js and .min.css files into the same directory as the Javascript and CSS files. Because my site has numerous skins, there are JS and CSS files located in numerous directories. I want to be able to add a task that runs after the AJAX Minifier that moves all .min.js and .min.css files to /min/ relative to the file location. So /Skin1/somescript.min.js would move to /Skin1/min/somescript.min.js and /Skin2/somescript.min.js would move to /Skin2/somescript.min.js.

The only way I know to accomplish a copy/move requires knowledge of the absolute directory (or should I say directory relative to the Project file) but I can't seem to find a way to move based on a directory relative to the file I'm moving.

Can this be done?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑,眼淚并存 2024-09-23 07:13:45
<CreateItem Include="wwwroot\**\*.min.js;wwwroot\**\*.min.css">
    <Output TaskParameter="Include" ItemName="FilesToMove" />
</CreateItem>

<Move SourceFiles="@(FilesToMove)" DestinationFiles="@(FilesToMove->'wwwroot\%(RecursiveDir)\min\%(Filename)%(Extension)')"/>

假设您使用 MSBuild 社区任务 中的移动任务。如果没有,您可以直接复制然后删除原始文件。

<CreateItem Include="wwwroot\**\*.min.js;wwwroot\**\*.min.css">
    <Output TaskParameter="Include" ItemName="FilesToMove" />
</CreateItem>

<Move SourceFiles="@(FilesToMove)" DestinationFiles="@(FilesToMove->'wwwroot\%(RecursiveDir)\min\%(Filename)%(Extension)')"/>

Assuming you're using the Move task from MSBuild community tasks. If not, you could just copy and then delete the originals instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文