Ramanujan summation can be used, and this summation method can be derived by invoking analytic continuation as follows. Consider the partial series $S(N)$ of a divergent series:

$$ S(N) = \sum_{k=1}^N f(k)$$

Let’s split this summation in two parts:

$$ S(N) = \sum_{k=1}^{p-1}f(k) + \sum_{k=p}^N f(k)$$

for some integer $p$. We then we apply the Euler–Maclaurin summation formula to the second summation:
$$ S(N) = \sum_{k=1}^{p-1}f(k) + \int_p^{N}f(x) dx + \frac{1}{2}[f(p) + f(N)] + \sum_{r=1}^{\infty} \frac{B_{2r}}{(2r)!}\left[f^{(2r-1)}(N) - f^{(2r-1)}(p)\right]$$

Here the summation over $r$ is usually a divergent asymptotic expansion, it may be written more rigorously as a finite summation plus a remainder term. We can then write $\int_p^N f(x)dx$ in terms of the primitive function as $F(N) - F(p)$. If we also extend the summation over $k$ to $p$ and subtract $f(p)$, we get:

$$ S(N) = \sum_{k=1}^p f(k) + A(N) - A(p)\tag{3}$$

where:

$$ A(u) = F(u) + \frac{f(u)}{2} + \sum_{r=1}^{\infty}\frac{B_{2r}}{(2r)!}f^{(2r-1)}(u)\tag{4}$$

Then we imagine that we could have introduced a parameter in the function $f(x)$, which for some range of the values of that parameter would have made the summation to infinity convergent. Then all the terms that are diverging in the limit of $N$ to infinity in (3) would tend to zero or some constant, and analytically continuing the result back to the value of the parameter that yields the original sum, would have the effect of setting all these diverging terms to zero. We can then do this directly in (3) as follows.

If we denote by $D(u)$ all the terms in $A(u)$ that we're going to set to zero in $D(N)$ and $c$ the constant term in there that we're going to keep, then we can write:

$$\displaystyle A(u) = D(u) + c + \mathcal{o}(1)$$

The constant $c$ can the only come from the primitive function, because after analytic continuation to a domain where the summation is convergent, all the terms in $A(N)$ tend to zero, except possibly $F(N)$. Using that $S(N)$ does not depend on $p$ allows us to take the limit of $p$ to infinity in (3). We can then write:

$$ S(N) = \lim_{p\to\infty}\left[\sum_{k=1}^{p}f(k) - D(p)\right]+ D(N) + \mathcal{o}(1)$$

Deleting the terms in $D(N)$ per the analytic continuation argument and also the terms that tend to zero, gets us to the summation result of:

$$ S = \lim_{p\to\infty}\left[\sum_{k=1}^{p}f(k) - D(p)\right]\tag{5}$$

We see that the constant term $c$ from the primitive function drops out. It's then convenient to define the primitive function such that this constant term is zero.
In case of the harmonic series we have $f(k) = \frac{1}{k}$ and $D(p) = \log(p)$, so we have:

$$S = \lim_{p\to\infty}\left[\sum_{k=1}^{p}\frac{1}{k} - \log(p)\right] = \gamma$$