Good-practices: How to reuse .csproj and .sln files to create your MSBuild script for CI?

前端 未结 1 1588
庸人自扰
庸人自扰 2020-12-18 01:53

What is the painless/maintainable way of using MSBuild as your build runner ? (Forgive the length of this post)

I was just trying my hand at TeamCity (which I must s

1条回答
  •  眼角桃花
    2020-12-18 02:20

    I didn't try TeamCity yet but did set up a Build environment for our new BizTalk project.

    Following the excellent advice of Sayed Ibrahim Hashimi on my own question before starting out, I created a set of MSBuild .proj and .targets scripts.

    The Core

    A central .targets script for the actual build steps you want to perform:

    
        
        
            
                $(ValidateDependsOn);
                Validate;
            
        
    
        
            
                $(PullDependsOn);
                PullFromVersionControl;
            
        
    
        
            
                $(BuildDependsOn);
                Build;
            
        
    
        
            
        
    
        
            
        
    
        
            
        
    
    

    The second core part are the configuration targets like you find them in your .csproj files

    
        
            Foo
        
    
        
            Bar
        
    
    

    The Projects

    The single .csproj itself is represented by a.targets file with just a collection of ItemGroups you need for building.

    
        
            
            
            
            
        
    
        
            
            
        
    
    

    Putting it together

    The .proj you are actually going to execute with MSBuild will import your Configuration, your Project (source code files) and the Core (Pull, Build and Deployment commands)

    
        
    
        
    
        
    
    

    Using this approach I was able to reuse the .targets containing the sources to build my some 50 projects in many different combinations instead of creating VS solutions to group them.

    I hope you'll find this useful - I can add more details if you're interested.

    0 讨论(0)
提交回复
热议问题