简体   繁体   English

Visual Studio - 生成后事件

[英]Visual Studio - Post-build event

I have a C# library I'm compiling in Visual Studio.我有一个正在 Visual Studio 中编译的 C# 库。 When that project successfully compiles, I want to create a.zip file.当该项目成功编译后,我想创建一个 .zip 文件。 However, I need to use a custom encoding.但是,我需要使用自定义编码。 For that reason, I need to use the .NET CreateFromDirectory method.出于这个原因,我需要使用 .NET CreateFromDirectory方法。 My question is, how do I use a .NET method from the post-build events in Visual Studio?我的问题是,如何在 Visual Studio 的构建后事件中使用 .NET 方法? Currently, I have the following:目前,我有以下内容:

Add-Type -Assembly 'System.IO.Compression.ZipFile'

[System.IO.Compression.ZipFile]::CreateFromDirectory(".", "../$(SolutionName).zip")

When I run this, I receive an error that says:当我运行它时,我收到一条错误消息:

Error   MSB3073 The command "Add-Type -Assembly 'System.IO.Compression.ZipFile'
[System.IO.Compression.ZipFile]::CreateFromDirectory(".", "../MySolution.zip")
" exited with code 123. MySolution  C:\Repositories\MySolution\MyProject.csproj 56  

What am I doing wrong?我究竟做错了什么? How do I run .NET methods from the post-build events in Visual Studio?如何从 Visual Studio 中的构建后事件运行 .NET 方法?

The system error code 123 means系统错误代码123表示

The filename, directory name, or volume label syntax is incorrect.文件名、目录名或卷 label 语法不正确。

If you are on Windows, use the backslash \ instead of the forward slash / as the directory separator, and try the command from a commandline first.如果您使用的是 Windows,请使用反斜杠 \ 而不是正斜杠 / 作为目录分隔符,并首先从命令行尝试该命令。 You also may need to use absolute paths or Visual Studio project path variables, as the runtime current directory of VS - by the time it runs the post build command - may be different from what you'd expect.您可能还需要使用绝对路径或 Visual Studio 项目路径变量,因为 VS 的运行时当前目录(在它运行构建后命令时)可能与您的预期不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM