# How to suppress undefined references in exercise answers when using noanswer option?

I'm using the exercise package to write exercises and their corresponding answers. I have hundreds of exercises, each in their own file. The exercises are to be included two separate documents. In the first, each exercise should appear without its answer, and in the second, they should appear with their answer. To do this, I'm using the package option noanswer in the first document. The problem is that in this first document, any references defined in an answer are reported as undefined even when the only reference to them is also in the answer.

For example:

\documentclass{article}

\usepackage{mwe}
\usepackage{float}

\begin{document}
\begin{Exercise}
\label{exe:some_exercise}
\blindtext
\end{Exercise}
\begin{figure}[H]
\centering
\includegraphics[width=.48\linewidth]{example-image-a}
\caption{MWE figure}
\label{fig:some_figure}
\end{figure}
\blindtext as shown in Figure~\ref{fig:some_figure}.
\end{document}


reports:

LaTeX Warning: Reference fig:some_figure' on page 1 undefined on input line 20


I've tried other package options like answerdelayed and then never calling \shipoutAnswer, but that has the same problem. How can I suppress the undefined reference warnings caused by the exercise answers which are not being included, but still see warnings for undefined references in the parts of the document that are being typeset?

EDIT:

I found this similar question with an answer but I do not know how to apply its answer to the exercise package.

Why do we get undefined references warning in exam class when labels are defined and used in solutions (and answers are not printed)?

\expandafter\let\expandafter\InitAnswer\csname @InitAnswer\endcsname

The reason of your problem is that the Answer text is normally processed in \vbox and the result is not used if [noanswer] option is set. It means that \ref needs to know the label, but the label is not written to the aux file, because \write aux{... label} is a part of the printed material in the \vbox which is unused. The asynchronous \write` primitive plays its role here.