简体   繁体   中英

Visual Studio - Post-build event

I have a C# library I'm compiling in Visual Studio. When that project successfully compiles, I want to create a.zip file. However, I need to use a custom encoding. For that reason, I need to use the .NET CreateFromDirectory method. My question is, how do I use a .NET method from the post-build events in Visual Studio? 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?

The system error code 123 means

The filename, directory name, or volume label syntax is incorrect.

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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