git - 如何在具有多个协作者的环境中使用本地化的 PostBuildEvent?

标签 git visual-studio msbuild visual-studio-2015

我有一个项目具有以下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>

这里,OutPutDirectory 显然是我自己安装的本地文件。默认值为 ..

此配置存储在项目的 .csproj 文件中,该文件还跟踪对其他程序集和项目中文件的引用等内容。

出于这个原因,我不能简单地忽略 git 中的文件,否则我对 .csproj 的其他更改都不会通过。

有什么方法可以保留我的本地化 PostBuildEvent 而不将其强加给其他协作者?

最佳答案

我通过设置用户帐户级别的环境变量解决了这个问题,并根据该变量使用它或使用默认值。

我只是用这个交换了原始的 PostBuildEvent 和周围的 PropertyGroup:

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

环境变量设置为 NUGETLOCAL,值为 "C:\Users\jeroen\Google Drive\NugetLocal\VSDiagnostics"(包括重音符号)。如果未设置该变量,它将使用默认目录,用户可以随时选择定义自己的目录。

代码可能不够漂亮,所以如果您看到改进请告诉我。

我对此进行了详细说明here .

关于git - 如何在具有多个协作者的环境中使用本地化的 PostBuildEvent?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30529126/

相关文章:

visual-studio - 在 VS 2017 的自托管 VSTS-BuildAgent 上构建失败,错误为 "The TransformWebConfig task could not be loaded[...]"

具有命名空间的元素的 XPath

visual-studio - Visual Studio 2010 或更高版本的功能区 UI?

visual-studio - Visual Studio 调试卡在 "Attaching to the web server"

Git 通过 HTTP 推送不激活远程 Hook

git - 智能 : Viewing diff of all changed files between local and a git commit/branch

c++ - GCC "Internal compiler error: Error reporting routines re-entered"(包含完整代码)

git - AssemblyVersion 与 Appveyor 版本一致

git - Bamboo 在源代码检查任务中间歇性失败并显示 "not a git repository (or any of the parent directories): .git"

git - 在执行 `git stash` 时保留更改