5

The problem:

I am trying to create a function that creates a hash code of the source code of my asp.net web application backend.

As long as nothing gets changed, this hash code needs to be identical. Even if I rebuild my project.

Does someone know, how I can do that?

What I tried:

The only working solution I found is to concat all important files to a big string and create a hash code out of it.

The problem of this solution is, that I have to add all the source files to the output directory, what shouldn't be done for security reasons.

Hope someone has a great idea =)

Thanks in advance!

Update:

I could solve my problem by enabling deterministic build as Renat suggested.

Just added the deterministic flag to my .csproj file as follows:

<Deterministic>True</Deterministic>
8
  • Could you generate a file hash for all the binaries in the output directory? stackoverflow.com/questions/50928253/… Commented May 15, 2019 at 6:23
  • 2
    May I ask why you're doing this? Commented May 15, 2019 at 6:25
  • @LasseVågsætherKarlsen Our software will be certified. We have to make sure that nothing gets changes in the source files. otherwise we have to certify the software again. Commented May 15, 2019 at 6:28
  • @MatthewEvans The binaries in the output directory are different on every build, because of the meta data. Commented May 15, 2019 at 6:29
  • @MatthewEvans you've found very low quality suggestion to compute hash of file... Something like stackoverflow.com/questions/38474362/… would be mor reasonable Commented May 15, 2019 at 6:29

1 Answer 1

4

Even if I rebuild my project

You may use Deterministic Build, then it will produce the same binaries in each build being made out of same source codes. Then you may get the hash of binaries.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for your suggestion. I will try that.
Thank you. I could get it working by adding the deterministic flag =)
Deterministic depends on far away to many variables, so not sure if I will recommend this option. The most easiest to fix probably will be the PathMap, but then you depends of specific versions of the compiler, libpath, etc. So building the same csproj in multiple setups, might still provide the wrong MVID

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.