How to use a localized PostBuildEvent in a multi-employee environment?

I have a project that has the following PostBuildEvent :

 <PostBuildEvent> if exist Diagnostic.nuspec if exist "$(SolutionDir)\packages\NuGet.CommandLine.2.8.2\tools\NuGet.exe" "$(SolutionDir)\packages\NuGet.CommandLine.2.8.2\tools\NuGet.exe" pack Diagnostic.nuspec -OutputDirectory "C:\Users\jeroen\Google Drive\NugetLocal\VSDiagnostics" </PostBuildEvent> 

Here, OutPutDirectory is obviously local to my own installation. The default value is . .

This configuration is saved in the .csproj project .csproj , which also tracks things like links to other assemblies and files in the project.

For this reason, I cannot just ignore the file in git, otherwise no other changes to .csproj will fail.

Is it possible to save my localized PostBuildEvent without imposing it on other collaborators?

+6
source share
2 answers

I solved this by setting the user account level environment variable, and depending on this, use it or use the default value.

I just changed the original PostBuildEvent and the surrounding PropertyGroup as follows:

 <Choose> <When Condition=" $(NUGETLOCAL) != '' "> <PropertyGroup> <PostBuildEvent>if exist Diagnostic.nuspec if exist "$(SolutionDir)\packages\NuGet.CommandLine.2.8.2\tools\NuGet.exe" "$(SolutionDir)\packages\NuGet.CommandLine.2.8.2\tools\NuGet.exe" pack Diagnostic.nuspec -OutputDirectory $(NUGETLOCAL)</PostBuildEvent> <RunPostBuildEvent>OnOutputUpdated</RunPostBuildEvent> </PropertyGroup> </When> <Otherwise> <PropertyGroup> <PostBuildEvent>if exist Diagnostic.nuspec if exist "$(SolutionDir)\packages\NuGet.CommandLine.2.8.2\tools\NuGet.exe" "$(SolutionDir)\packages\NuGet.CommandLine.2.8.2\tools\NuGet.exe" pack Diagnostic.nuspec -OutputDirectory .</PostBuildEvent> <RunPostBuildEvent>OnOutputUpdated</RunPostBuildEvent> </PropertyGroup> </Otherwise> </Choose> 

The environment variable is set to NUGETLOCAL with the value "C:\Users\jeroen\Google Drive\NugetLocal\VSDiagnostics" (including accents). If the variable is not set, it will use the default directory, and the user has the opportunity to define it anytime he wants.

The code is probably not as pretty as it may be, so let me know if you see an improvement.

I elaborated on this here .

+3
source

As I mentioned in the comments, I think that this should be done only for Release builds. An action can be skipped completely if it is not built in the Release configuration using the ConfigurationName macro.

 if $(ConfigurationName) == Release ( if exist Diagnostic.nuspec if exist "$(SolutionDir)\packages\NuGet.CommandLine.2.8.2\tools\NuGet.exe" "$(SolutionDir)\packages\NuGet.CommandLine.2.8.2\tools\NuGet.exe" pack Diagnostic.nuspec -OutputDirectory "C:\Users\jeroen\Google Drive\NugetLocal\VSDiagnostics" ) 

Here is a list of all available macros . I also understand that all environment variables are imported as macros , so you can come up with something more elegant based on the user profile and the existence of a subdirectory.


If you think about it, you can use the standard USERPROFILE environment variable and just check if the path exists.

  if exist "$(USERPROFILE)\Google Drive\NugetLocal\VSDiagnostics"( if exist Diagnostic.nuspec if exist "$(SolutionDir)\packages\NuGet.CommandLine.2.8.2\tools\NuGet.exe" "$(SolutionDir)\packages\NuGet.CommandLine.2.8.2\tools\NuGet.exe" pack Diagnostic.nuspec -OutputDirectory "$(USERPROFILE)\Google Drive\NugetLocal\VSDiagnostics" ) 

However, this has some limitations. It will only work on Windows. Linux uses a different variable for the user profile path.

+2
source

Source: https://habr.com/ru/post/988153/


All Articles